PDA

View Full Version : ftp transfer via script



Hekabe
May 31st, 2013, 12:47 AM
I'm writing a bash script to automatically update a local directory from a remote directory on an FTP server. I'm using the following code to get an automatic login, but I've run into trouble.

ftp -p -i -v ftp.myhostname.org <<EOF
username
password
EOF

It recieves the username input, but then it prompts for the password. Any ideas?

steeldriver
May 31st, 2013, 01:06 AM
http://en.wikipedia.org/wiki/Expect#Examples

Hekabe
May 31st, 2013, 11:59 PM
Alright, that's working. Thanks. One other question. Is there a way to do a recursive "newer" get in FTP using the ftp command?

ofnuts
June 2nd, 2013, 10:13 PM
http://en.wikipedia.org/wiki/Expect#Examples

Of "ftp -n" followed by a "user" command. Or you keep the login info in a .netrc file (see "man 5 netrc").

For your other problem, check the ftp command "newer", which is an intelligent "get". Otherwise there are FTP support libraries for many languages (Python, Java...)