SFTP with Password

Hi Guys,

I need to know how can i achieve SFTP "with" password in a shell script.
I have already done passwordless key generation thing and it is working but at the moment i am interested in passing a password.

And another question I have is say i have a.ksh and b.sh scripts...Can i invoke a.ksh in b.sh

Regards
Arpit

ssh/sftp/scp/sudo/su/et al are all designed to stop you from injecting stored plaintext passwords. This is a subtle hint, written in mile-high flashing neon letters, that it's a really bad idea -- it's almost impossible to keep retrievably-stored passwords safe. "interactive password authentication" means "password typed by a human being in realtime authentication" and nothing else is supposed to do.

To this end, they read from the terminal, which your program doesn't control and not from standard input, which you can redirect. To even try to forcefeed it, you'll need to install a third-party brute-forcing utility like expect and write a big ugly script in it. It won't happen natively like keys do.

That's why they made the much safer key-based authentication, to remove the need and temptation to inject passwords.

1 Like

Please edit and remove the 2nd question, and post as its own item. This will help future users learn from the questions and answers.

if a.ksh has

#!/bin/ksh

as the first line, yes:

/path/to/a.ksh

Otherwise:

ksh -c /path/to/a.ksh

Have a look at lftp. It supports username and password as command line options.

...which would pretty much broadcast the username and password publicly on the system if you did so -- anyone could ps aux and see...

You could use either

Net::SFTP

or

Net::SFTP::Foreign

perl modules...