您现在的位置是:网站首页> 编程资料编程资料
使用FTP下载目录,即FTP命令批量自动下载的bat文件_DOS/BAT_
2023-05-25
452人已围观
简介 使用FTP下载目录,即FTP命令批量自动下载的bat文件_DOS/BAT_
FTP不支持目录的下载,不过FTP命令提供了mget命令,允许多文件下载,但每下载一个文件都需要确认,不能自动完成。本文主要介绍使用批处理,结合FTP的相关命令来实现批量文件的下载,以便达到目录下载的目的。
ftp -s:filename hosts >result.txt 执行脚本,并将结果定向输出到result.txt
脚本内容,如
cd mydir
ls
bye
可以将mydir命令列出
然后使用批处理分析result.txt
从150 Opening ASCII mode data connection for file list.的下一行开始算,直到226 Transfer complete都是要下载的内容
然后用批处理加ftp脚本,使用get命令逐个下载
G:>ftp -?

Transfers files to and from a computer running an FTP server service
(sometimes called a daemon). Ftp can be used interactively.

FTP [-v] [-d] [-i] [-n] [-g] [-s:filename] [-a] [-w:windowsize] [-A] [host]

-v Suppresses display of remote server responses.
-n Suppresses auto-login upon initial connection.
-i Turns off interactive prompting during multiple file
transfers.
-d Enables debugging.
-g Disables filename globbing (see GLOB command).
-s:filename Specifies a text file containing FTP commands; the
commands will automatically run after FTP starts.
-a Use any local interface when binding data connection.
-A login as anonymous.
-w:buffersize Overrides the default transfer buffer size of 4096.
host Specifies the host name or IP address of the remote
host to connect to.

Notes:
- mget and mput commands take y/n/q for yes/no/quit.
- Use Control-C to abort commands.

echo cd autoruns>ftp.txt
echo mget *>>ftp
大致想法如下:
ftp -s:filename hosts >result.txt 执行脚本,并将结果定向输出到result.txt
脚本内容,如
cd mydir
ls
bye
可以将mydir命令列出
然后使用批处理分析result.txt
从150 Opening ASCII mode data connection for file list.的下一行开始算,直到226 Transfer complete都是要下载的内容
然后用批处理加ftp脚本,使用get命令逐个下载但实际过程中发现,在FTP脚本中使用get有问题,提示参数错误,无法使用。
查看了ftp的帮助ftp -?
G:>ftp -?
Transfers files to and from a computer running an FTP server service
(sometimes called a daemon). Ftp can be used interactively.
FTP [-v] [-d] [-i] [-n] [-g] [-s:filename] [-a] [-w:windowsize] [-A] [host]
-v Suppresses display of remote server responses.
-n Suppresses auto-login upon initial connection.
-i Turns off interactive prompting during multiple file
transfers.
-d Enables debugging.
-g Disables filename globbing (see GLOB command).
-s:filename Specifies a text file containing FTP commands; the
commands will automatically run after FTP starts.
-a Use any local interface when binding data connection.
-A login as anonymous.
-w:buffersize Overrides the default transfer buffer size of 4096.
host Specifies the host name or IP address of the remote
host to connect to.
Notes:
- mget and mput commands take y/n/q for yes/no/quit.
- Use Control-C to abort commands.
发现 -i 参数可以去除mget的提示,经过测试,实现了如下脚本(使用了匿名登入,如果非匿名,可以修改登入脚本):
echo cd autoruns>ftp.txt
echo mget *>>ftp点击排行
本栏推荐
