ftp
on windows
Auto download
The
following provides examples of how to automate ftp by using
a batch file that will download a file. The batch file uses
another file that contains the login, password and download
instructions.
This
example...
- connects
to the ftp site ftp.site.com
- downloads
the file update.exe
- records
the transaction results in a the a log file, ftp.log.
download.bat
whattodo.txt
top
of page
ftp on Linux (Unix)
Auto
download
The following
example explains how to automate an ftp connection. Once the scripts
are created, you can automate them using cron or at jobs. For
example, every night you may want to copy the same set of files
from one server to another.
The basic
trick to accomplish this technique is that it requires two
files. The login and password for ftp
can not be incorporated in the same script that issues the ftp
commands. Linux provides a file .netrc that contains the
necessary login and password information. .netrc
This file
must be located in the users home directory with the permissions
set to executable by the owner only. (chmod go-rwx .netrc)
There are three entries in this file
machine
sample.ftpsite.com
login anonymous (or
user name)
password mymail@mydomain.com (or
user's password)
download.sh
This file
contains the instructions for what you want the ftp connection
to do. It should be set to be executable. (chmod
ugo+x download.sh)
ftp
<<**
open sample.ftpsite.com
cd pub
bin
mget newfile*
bye
**
What
it does
- Connects
to the ftp site: sample.ftpsite.com
- Logs
in with the user's name: anonymous
- Uses
the password: mymail@mydomain.com
- On
the ftp site, changes to the directory: pub
- Sets
binary transfer mode
- Copies
all files that start with newfile
- Exits
the ftp site
Using at
You can
automate this as a one-time procedure by using the
at command...
- at
1:00 am
- download.sh
(should use the full path where download.sh
resides)
- ^D
Using cron
You can
automate this to occur everynight at 1 AM...
- crontab
-e
- Add
a new line 0 13 0 0 0 download.sh
(should use full path where download.sh
resides)
top
of page |