Automatic FTP script

Source: Internet
Author: User
Tags ftp site ftp transfer

 

Automatic FTP script

Use the following script to implement automatic FTP, transfer the files you need to the desired place, or capture the files from somewhere.

CD/path_you_want_to_upload (download)

FTP-n <-EOF

Open ip_address

User Username Password

ASCII (or bin)

Put * (or get)

Bye

EOF

 

The following code is described in detail:

1. CD/path_you_want_to_upload (download)

First, you will enter the directory where the file to be uploaded exists, or the directory where you want to download the file from an FTP. This saves the trouble of modifying the local path after you enter the FTP site.

2. FTP-n <-EOF

Because it is a script, we need to define an end symbol for this ftp script. Here, the end character is "EOF ". You can also define others by yourself. However, we recommend that you use "EOF", which means end: End of file in most programming languages.

3. Open ip_address

Indicates connecting to the FTP site. The ip_address here is the IP address of the FTP site.

4. User Username Password

This is the user name and password you entered the FTP site. The combination of the above two is equivalent to the FTP: // username: [email protected] _ address method that we often use when entering the FTP site through a browser.

5. ASCII (or bin)

We all know that there are two FTP Transfer Methods: ASCII and binary. Here is the method you want to transmit. This is important because it determines whether the file you transfer or obtain is available.

6. Put * (or get)

Put * means to transfer all the files in the path of the first CD to the FTP site just connected. Of course, you can specify one or more files, not necessarily all. Get indicates that the file in the FTP and directory of the FTP site that you just entered is obtained to the local path where the first CD command is entered. Of course, if the file you need is not in the FTP root directory, you need to use the CD command to modify the current path of the FTP site before using this command.

7. Bye

After completing the work, the FTP site is disconnected.

8. EOF

This symbol has been mentioned before. When the script encounters this symbol, it knows it should end.

One way to be lazy is to write the above script into a function, and then call this function when necessary.

Autoftp ()

{

CD

FTP-n <-EOF

Open ip_address

User Username Password

ASCII (or bin: Binary)

Put (or get)

Bye

EOF

}

 

 

In addition, you need to note that after this program, you need to determine whether the automatic FTP is successful-that is, whether the transfer or acquisition is successful. The judgment here also has two ideas:

1. If it is obtained, check whether it is obtained locally. If it is a transfer, you need to call the automatic FTP script again to determine whether the transfer is successful in the correct directory on the FTP server. However, this method is obviously "bulky;

2. Common shell Methods: $? If the return value is 0, it indicates success, and if the return value is not 0, it indicates that success is not successful. However, what I mentioned should be noted here. In fact, no matter whether automatic FTP is successful or not, the return value is actually 0. This will cause a lot of troubles. Why? Don't forget. In fact, your final code script is EOF. Therefore, it will fail no matter whether it is automatically transmitted over FTP or obtained, in fact, this normal ending symbol causes the script to "end normally". Therefore, $? The returned value is 0.

 

 

 

 

Automatic FTP script

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.