Re: bash scripting: automatically download via ftp
Tony Nugent <[email protected]>
| Newsgroups | gmane.linux.redhat.release.enigma |
|---|---|
| Organization | Linux Works |
| Message-ID | <[email protected]> |
On Sat Mar 22 2003 at 20:08, Nguyen Vu Hung wrote: > Hello all, > > How can I write a bash script that connect to a ftp > server, enter username and password( hardcoded in the > script), cd to /some/dir and get some files? You run ftp with an ~/.netrc file that has an entry for the ftp server you want to connect to. For example, this is generated by a cron job... this entry in /root/.netrc will automatically generate output with a list of the currently available virus definition files at the McAfee ftp site. (This is on a busy network server with lots of windows boxes, they use their product). ========8<--------- cut ---------------- # if you use this, change email address in the password machine ftp.nai.com login anonymous password [email protected] macdef init prompt lcd /usr/local/uvscan cd virusdefs/4.x dir bye ========8<--------- cut ---------------- With that entry in ~/.netrc, all you need to do is this: $ ftp ftp.nai.com The init "script" will carry out those commands, and log out. The script language is basic but functional enough - a sort of macro language with a few extensions. On this rh73 box I have a man page for netrc(5). I have several cron scripts that re-write /root/.netrc to do particular tasks with ftp. Continued dxample: after the initial check, if the cron script finds that there are virus updates available, then ~/.netrc is re-written by the script to login again but this time download the necessary files. And so the windows clients are kept happy. > Thanks Have fun! Cheers Tony