SFTP automation with password/passphrase

Hi All,
We have a special requirement from our client, we need to automate one of the sftp job with password authentication. I know sftp can be automated with Key authentication, but this is not what I am looking for.

Can some body help me, a method like .netrc in FTP automation or like sftp user/password@server method.

Thanks
Shihab

This can be done with either batch mode, or with external language, such as TCL/Expect. Please use our search function, and I'm sure you will find your option, personally I have posted at least 5 times sample Expect code for SFTP automation.
In both cases the password will be placed in a plain format, so this has security risk.

Thanks Sysgate for your reply..
Unfortunately we cannot use expect or any other external language. Is there any way to do it via batch mode ?

No, there is no standard way to do it via batch mode. However you can set up scp to do what you want via batch mode.

Hi, I have exactly the same situation as mentioned by Shihab above. I can not use ssh/public/private keys. I can not use expect. Is there a way for this ? What do I need to setup SCP with to be able to do this?
Basically I want to trf a file frm server 1 to server 2. I cant use ftp. I have to use sftp or scp. I cant use expect/other tools. I cant use ssh/public/private keys setup.
Pl suggest a solution.

No, there is no solution to use sftp with password in a batch mode by simple shell.

You have to resort to expect/perl/java...

I forgot to mention in my previous post that you could also use lftp to automate a password prompt sftp session. lftp is standard on a lot of GNU/Linux distributions and is available for HP-UX, Solaris etc.

Here is a short script to retrieve a file called tmpfile from /tmp on a server using lftp in sftp mode

#!/bin/sh

HOST=yourservername
USER=yourusername
PASS=yourpassword

echo "sftping file ..."

lftp -u ${USER},${PASS} sftp://${HOST} <<EOF
cd /tmp
get tmpfile
bye
EOF

echo "done"