Shell script, automatically log on to FTP, download files

Source: Internet
Author: User

(1) automatically log on to FTP

(2) Place the downloaded file to the specified local directory

(3) determine whether there are any files to be downloaded on the FTP server

#! /Bin/bash
# Create a directory with the downloaded file in the format of 2013-06-17
Datestr = $ (date + % Y-% m-% d)
Mkdir/home/$ datestr
# Connect to FTP to obtain the information and store it in FTP. log.
FTP-I-n 192.168.xxx.xxx <!> FTP. Log
User name passwd
Ls
Bye
!
##### Determine from the log whether there is a directory to be downloaded
Grep $ datestr ftp. Log
If [$? -EQ 0]
Then
FTP-v-N 192.168.xxx.xxx <EOF
User name passwd
Binary
CD/sd1/$ datestr
LCD/home/$ datestr
Prompt
Mget-C *
Close
Bye
EOF
Else
Echo "the download directory does not exist"
Fi

Related Article

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.