Linux下可以使用以下命令,下载远端FTP目录下所有的文件,递归所有子目录。对服务器迁移很有用。
1
|
wget -nH -m –ftp-user=your_username –ftp-password=your_password ftp://your_ftp_host/*
|
解释:
-nH:不创建以主机名命名的目录。
–cut-dirs:希望去掉原来的目录层数,从根目录开始计算。如果想完全保留FTP原有的目录结构,则不要加该参数。
-m:下载所有子目录并且保留目录结构。
–ftp-user:FTP用户名
–ftp-password:FTP密码
ftp://*.*.*.*/*:FTP主机地址。最后可以跟目录名来下载指定目录。
例子:
1
|
wget -nH -m –ftp-user=tom –ftp-password=123456 ftp://192.168.19.1/tom/
|
当然,如果FTP目录下文件数量特别多,效率最高的做法是先打个压缩包,然后再下载。实在没办法,就用上述方法自动下载吧。
You can use ncftpget command to download entire ftp directory and sub directories from remote ftp server. Let us say you would like to download /www-data directory and all subdirectories inside this one from ftp.nixcraft.net server. You need to use ncftpget command.
Install ncftp client
ncftp client software can be downloaded from http://www.ncftp.com/ncftp/ and works with FreeBSD, Solaris and all most all UNIX variant. You can also run command as follows to install ncftp:
$ sudo apt-get install ncftp
FTP get directory recursively
ncftpget is Internet file transfer program for scripts and advance usage. You need to use command as follows:
$ ncftpget –R –v –u "ftpuser" ftp.nixcraft.net /home/vivek/backup /www-data
Where,
- -R : Copy all subdirectories and files (recursive)
- -v : Verbose i.e. display download activity and progess
- -u “USERNAME” : FTP server username, if skipped ncftpget will try anonymous username
- ftp.nixcraft.net : Ftp server name
- /home/vivek/backup : Download everything to this directory
- /www-data : Remote ftp directory you wish to copy
If you get an error which read as follows:
tar: End of archive volume 1 reached
tar: Sorry, unable to determine archive format.
Could not read directory listing data: Connection reset by peer
Then add –T option to ncftpget command:
$ ncftpget –T –R –v –u "ftpuser" ftp.nixcraft.net /home/vivek/backup /www-data
Where,
- -T : Do not try to use TAR mode with Recursive mode