如何创build.BAT
文件从FTP服务器下载文件或文件夹? (并replace它现有的文件)(我们有像ftp://me:mypass@example.com/file.file
(或http://example.com/file.file )和绝对文件链接如C:\Users\UserName\Some mixed Русский English Adress\file.file
)(只使用本机窗口(XP的Vista的win7等)BATfunction和文件)
这里是一个如何自动化内置ftp.exe
工具的例子:
这个例子是关于上传的,但是原理是一样的(只是使用get
而不是put
)。
不过,因为这只是“管道命令”进入ftp.exe,我建议不要这样做生产质量批处理文件(没有错误处理等),而是使用一些外部工具。 我只提供了这个答案,因为你明确地要求一个只使用Windows内置命令的解决方案。
编辑:这里有一个具体的例子:
REM replace this with your user name and password REM make sure there is no space between the pwd and the >> echo user me > getftp.dat echo mypass>> getftp.dat echo binary >> getftp.dat REM replace this with the remote dir (or remove, if not required) echo cd remoteSubDir >> getftp.dat REM replace this with the local dir echo lcd C:\Users\UserName\SomeLocalSubDir >> getftp.dat REM replace this with the file name echo get file.file >> getftp.dat echo quit >> getftp.dat REM replace this with the server name ftp -n -s:getftp.dat example.com del getftp.dat
我以前在批处理文件中使用过WGET来完成这个任务。 http://www.gnu.org/software/wget/
大多数Windows操作系统内置的命令行FTP程序是可编写脚本的 。 你只需要创建一个文本文件,如果你手动运行它(每行一个命令)就可以发送这个命令,然后像下面这样执行它:
ftp -s:download.scr
你使用的是什么FTP客户端软件? 它是可脚本化的吗? 如果是这样,创建一个脚本,下载文件并从批处理文件中调用此脚本。
我正在用WS_FTP做这个。