How to automate sftp without using expect script?

How to automate sftp with out using expect script?

My batch file has the password but it is not taking. Please see below.

I want to use this sftp connection in a loop for pushing new files in a directory one at a time. Hence I can not use an expect script.

bash-2.05$ /usr/bin/sftp -b /tmp/Cap_batch username@89.202.125.15
Connecting to 89.202.125.15...
username@89.202.125.15's password:

bash-2.05$ more /tmp/Cap_batch
@passwd!




It would be great if some body can suggest a possible solution.

You'll have to set up key authentication so you will be able to use a here-script for automation.
sftp does not work with feeding a password in a script. That's unsecure and that's why keys should be used.
If possible and key authentication is set up, maybe use scp instead of sftp. Might be more comfortable than using a here-script.

For how to set up a passwordless key based communication with ssh/scp/sftp search this forum or the web, there are plenty of guides.
Don't forget to enter no password when creating the key pair with ssh-keygen.

Thanks Zaxxon for the prompt reply.

But sftp connection is enabled between a client site. Hence ssh key can not be implemented... :frowning: any other solution...??

Hint: SFTP is but a sub-system of SSH...

Oh Sorry for the confused reply..! I know that... What I meant is, I can't exchange the ssh keys to the client for some reasons. Any other solutions?

Talk to the client, and ask them what they would prefer:

  • Get a public key from you, and implement it so that you can authenticate yourself with it
  • Have the password for their service passed from an expect script where it's possibly easy for everyone to read