ftp

 

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

    echo Start of download>ftp.log
    ftp -s:whattodo.txt sample.ftpsite.com>>ftp.log
    echo End of download>>ftp.log

whattodo.txt

    anonymous (can be replaced with actual user's name)
    myname@mydomain.com (can be replaced with actual user's correct password)
    cd pub/software
    lcd d:\data
    bin
    hash
    get update.exe
    close
    bye

    What is does

    1. Creates a log file that contains the status of the ftp connection: ftp.log
    2. Connects to the ftp site: sample.ftpsite.com
    3. Logs in as: anonymous
    4. With a password of: myname@mydomain.com
    5. On the ftp site, changes to the directory: pub/software
    6. On local PC, changes to the directory: d:\data
    7. Sets binary transfer mode
    8. Copies the file update.exe from pub/software to d:\data
    9. Exits from the from the ftp site

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

    1. Connects to the ftp site: sample.ftpsite.com
    2. Logs in with the user's name: anonymous
    3. Uses the password: mymail@mydomain.com
    4. On the ftp site, changes to the directory: pub
    5. Sets binary transfer mode
    6. Copies all files that start with newfile
    7. Exits the ftp site

Using at

You can automate this as a one-time procedure by using the at command...

  1. at 1:00 am
  2. download.sh (should use the full path where download.sh resides)
  3. ^D

Using cron

You can automate this to occur everynight at 1 AM...

  1. crontab -e
  2. Add a new line 0 13 0 0 0 download.sh (should use full path where download.sh resides)

top of page

 

Services | Products | Support | What's New | Online Shopping | Online Help | Privacy Policy | Legal Stuff

Email us at Info@AHinc.com
© 1993-2005 Advanced Horizons, Inc. - All Rights Reserved