SFTP help

Hi Guys,

I am able to create a file with all the sftp command required.

I was able to ftp the files in the similiar fashion using ftp command. The following i used for ftp.

ftp -n < $filename 

But when i try the same for Sftp. i am getting error.

The file i am creating is in the following format.

open <Targetip>
user <USERID> <PASSWORD>
verbose on
cd <LOCATION>
lcd <SOURCE LOCATION>
mput *
close
bye

This will run in a loop changing the Targetip and Source Location.

Can somebody help me in running this SFTP file.

Cheers!!!!!!!!!!!!!

Can you try sftp with -b switch ?

sftp -b batchfile

Batch mode reads a series of commands from an input batchfile instead of stdin Since it lacks user interaction it should be used in conjunction with non-interactive authentication. sftp will abort if any of the following commands fail: get , put , rename , ln rm , mkdir , chdir , lchdir and lmkdir

@codemaniac,,,

Yeah i tried it,,,

But i am not able to pass the password.. as i have to pass it in the below format

sft -b batchfile [user@]host

But my question is how to pass the password?????

Try putting your remotehost , username and password and every sftp command in the batch file .Then trigger sftp -b batchfile .

@codemaniac,, yeah i tried that too...
It was giving me the same error.

Kindly post the error you get as it would help forum members here to derive at an appropriate solution. If password prompt is your problem in SFTP then you would need to generate public/private keys in your unix box. It has been explained here

I created a file as below.

 
remotehost=XX.XX.xxx.x
username=<USERID>
password=<PASSWORD>
cd /home/oraadf/Documents/
lcd /webmasters/report_repository/SGM
bye

I used the following command

sftp -b filename

I am getting the following error.

 
usage: sftp [-1Cv] [-B buffer_size] [-b batchfile] [-F ssh_config]
            [-o ssh_option] [-P sftp_server_path] [-R num_requests]
            [-S program] [-s subsystem | sftp_server] host
       sftp [[user@]host[:file [file]]]
       sftp [[user@]host[:dir[/]]]
       sftp -b batchfile [user@]host

Giving username and password in a SFTP batch file does not seem to work. You would need to generate a public/private key to have password-less authentication. You can check here having similar issue. The command sftp -b filename is not correct, as the error says it should be as ssh -b filename username@host , but again this will prompt for password in that case you would need to generate a password-less login as stated earlier.

@michaelrozar17,,, it will work in development environment, but my client will not agree to it in the production environment, as anyone with userid can ftp any files...

Ok. But the same is applicable even if you use the ftp -n < filename command right..? Anyone with the userid could transfer files.If im not wrong.