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.