Several methods of downloading FTP files in Linux __linux

Source: Internet
Author: User

One, the simplest method: wget

The following command is used to download all files in the specified directory on the FTP server

wget ftp://ip:port/*--ftp-user=xxx--ftp-password=xxx-r
The-r parameter represents a recursive download;

You can use--directory-prefix=/mypath/to specify the storage path after download; The-NH option does not create a directory structure on the server locally

Another confusing option is--delete-after, which is not used to delete the downloaded files on the server, but to delete the local machine;

Wget is wget rather than wput, it can only download operations, does not support any write operations on the FTP server, such as deletion.

Second, can delete the file method: Lftp

The project requirement is to download all the files in the specified folder on the FTP server, and delete them after downloading, wget can not meet the requirements, so rewrite the following script.

The mget command can download multiple files, the-e parameter indicates that the files on the server are deleted after downloading.

#!/bin/bash
#指定ftp服务器的ip
serverip=1.2.3.4
#指定ftp服务器的ftp用户
serveruser=root
# Specifies the FTP server's FTP user password
serverpass=123456
#指定client主机本地下载文件存放的目录
localdir=./data
logfile=. /log/ftp_download.log
#指定server主机的ftp目录
remotedir=./
#指定server主机的主机名
host=test_host
# Switch to the directory CD $localdir the local download file
#输入开始备份的信息
echo "Starting FTP Download on" $host
#连接ftp服务器/
usr /bin/lftp << EOF
open $serverip
user $serveruser $serverpass
#切换到server主机的ftp目录
echo "CD" $ Remotedir
cd $remotedir
#列出ftp服务器ftp目录中文件列表并存放到client中的 $localdir
ls. >> $logfile
# Download all files in the FTP server FTP directory
mget-e *.txt
#退出ftp服务器
bye
Third, other methods

The FTP command in the system, and the powerful curl.

Curl supports FTP, FTPS, GOPHER, HTTP, HTTPS, IMAP, Imaps, LDAP, LDAPS, POP3, Pop3s, RTMP, RTSP, SCP, SFTP, SMTP, Smtps, TELNET and T FTP, easy to call in your own program. Cookies, proxies, passwords, and certificate authentication are also supported. Very powerful.

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.