~/.netrc

Automating ftp transfers can be a very useful thing to do. Accompany this with an hourly cron job and you can backup sensitive data remotely, or keep two servers running in sync with the same data. To automate an FTP transfer you will need to create a .netrc file in your home directory. The .netrc file needs to contain the following information: machine, username, and password. The information needs to be seperated by whitespace (space, tab, newline) with the correct information following. That first line of information will simply log you into the FTP server.

To automate transfering a specific file you will want to make a macdef (macro definition) on the first line. Placing macdef init on the first line causes that macro to be executed promptly after connection. You will more then likely want to set the file transfer method to binary instead of ascii. You can do this by specifying binary in your macro. See below for an example.

Note: you will need to leave the last line of the file blank otherwise you will get a macdef error.


machine ftp.cdrom.com login username password password
macdef init
binary
get /games/game1.zip /home/username/game1.zip
quit



See Also: man netrc
Questions or comments? Email me!