Scripted SFTP command line file transfer Mac OS X

file-transferscriptsftp

I'm working with someone who's been doing simulations on various computers and FTPing the results to a website using a script and the basic mac ftp command basically something like (this is not exact just what i remember from when i last looked at it)

ftp -i username@host password
cd /dir/
put file 1
put file 2
...

and so on…

I need to upgrade this process to use SFTP for security purposes, but there's no way that I can tell to put the password in a single line script for the SFTP program that's built into mac OS X. Is there some other way to do this? I tried using something called LFTP which seemed to connect to the server but the files would always stay at 0% when they were trying to transfer. Any help would be appreciated.

Best Answer

I guess i need to generate a key from the server itself and provide it to the user then they can connect just using the username and the key will authenticate them right?

No. Generate the key on client (ssh-keygen) and upload the public key to server. For example using ssh-copy-id, if the ssh is allowed on the server. There are many how-to's around the internet, so I believe you will be able to figure out.

Then connecting would work like sftp username@host (without password). If you have some batch, you can provide it to sftp using -b option. For more info, consult manual pages for sftp or the other above mentioned tools.