Monday 8 September 2008

Automating FTP transfer with linux

edit file ~/.netrc to contain

machine sample.ftpsite.com
login anonymous (or user name)
password mymail@mydomain.com (or user's password)



Make sure you:
chmod 600 ~/.netrc

To keep your passwords secure.

The ftp client will check the contents of this file when performing an ftp connection and will use the login and password when the machine matches one of the entries in the file. This is useful when writing a script to automate file transfer (as part of a cronjob for example) as no user intervention is necessary.


The FTP script itself might look like:



open sample.ftpsite.com
cd backupdir
lcd mylocalbackups
put backupfile.log



That script (remember to chmod +x scriptname) can be added to the cron daemon.

No comments: