replacing ftp with sftp in the script....

Hi,

I have the following bash script(related to ftp) that read the parameters from the properties file and then transfer some files to the remote machine...

following is the bash script ....

#!/bin/sh

. ftp.properties

ftp -vin >> ftp.log <<-!
        open $RemoteIp
        user $userid $password
        cd $DestFolder
        lcd $SrcFolders
        put $SourcefilePattern
        bye
        !

Now in the above scripT, I am using ftp what if I cahange the ftp in the Sftp...what effect would it bring...please guide me on that..!!:confused:

I think you cannot supply password in batch (non-interactive) mode in SFTP (unless you are using automation tools like expect see (How To Expect | Linux Magazine). I would think you would be much better off using key based password-less authentication (see Password-less logins with OpenSSH).

Check below script to see whether it satisfies yor reuqrement.

#!/bin/sh
. ftp.properties

sftp -vin >> ftp.log <<EOF
open $RemoteIp
user $userid $password
cd $DestFolder
lcd $SrcFolders
put $SourcefilePattern
bye
EOF

Hi smilesavvy,
as shown by you have added the sftp in place of ftp...as shown below...

#!/bin/sh
 . ftp.properties
  sftp -vin >> ftp.log <<EOF 
open $RemoteIp
 user $userid
 $password
 cd $DestFolder
 lcd $SrcFolders
 put $SourcefilePattern
 bye
 EOF

could you please explain what additional advantages does sftp gives over ftp...?:confused:

I would suggest you to check the MAN page.

sftp is an interactive file transfer program, similar to ftp, which performs all operations over an encrypted ssh transport. It may also use many features of ssh, such as public key authentication and compression. sftp connects and logs into the specified host, then enters an interactive command mode.

The second usage format will retrieve files automatically if a non-interactive authentication method is used; otherwise it will do so after successful interactive authentication.

The third usage format allows sftp to start in a remote directory.

The final usage format allows for automated sessions using the -b option. In such cases, it is necessary to configure non-interactive authentication to obviate the need to enter a password at connection time

1 Like

Hi smilesavvy,

Thanks a lot for the valuable information, I will now replace the ftp and use sftp in my script.,,thanks a lot again..!!:o

Is there a reason why you are not using scp? (can be configured to not ask for passwd...)

Probably because sftp looked similar enough to hopefully be an easy replacement...