windows 如何创建 .BAT 文件以从 HTTP\ftp 服务器下载文件?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2866787/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 07:19:52  来源:igfitidea点击:

How to create a .BAT file to download file from HTTP\ftp server?

windowsftpbatch-file

提问by Rella

How to create a .BATfile to download file or folder from FTP server? (and replace with it existing file) (we have links like ftp://me:[email protected]/file.file(or http://example.com/file.file) and absolute file link like C:\Users\UserName\Some mixed Русский English Adress\file.file) (using only native windows (xp vista win7 etc) BAT functions and files)

如何创建.BAT文件以从 FTP 服务器下载文件或文件夹?(并用它替换现有文件)(我们有类似ftp://me:[email protected]/file.file(或http://example.com/file.file)的链接和类似的绝对文件链接C:\Users\UserName\Some mixed Русский English Adress\file.file)(仅使用本机窗口(xp vista win7 等)BAT 功能和文件)

采纳答案by Heinzi

Here is an example of how to automate the built-in ftp.exetool:

以下是如何自动化内置ftp.exe工具的示例:

The example is about uploading, but the principle is the same (just use getinstead of put).

例子是关于上传,但原理是一样的(只是用get代替put)。

Still, since this is just "piping commands" into ftp.exe, I recommend not to do this for production-quality batch files (no error handling, etc.), but to use some external tool instead. I provided this answer only because you explicitly asked for a solution that only uses Windows built-in commands.

尽管如此,由于这只是“管道命令”到 ftp.exe 中,我建议不要为生产质量的批处理文件执行此操作(无错误处理等),而是使用一些外部工具。我提供这个答案只是因为您明确要求只使用 Windows 内置命令的解决方案。

EDIT: Here's a concrete example:

编辑:这是一个具体的例子:

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

回答by ewall

The command-line FTP program that's built-in to most Windows operating systems is scriptable. You just need to create a text file with the commands you would send if you were running it by hand (one command per line), then execute it like this:

大多数 Windows 操作系统内置的命令行 FTP 程序是可编写脚本的。您只需要使用手动运行时将发送的命令创建一个文本文件(每行一个命令),然后像这样执行它:

ftp -s:download.scr

回答by JM.

I have previously used WGET in a batch file to accomplish this. http://www.gnu.org/software/wget/

我以前在批处理文件中使用过 WGET 来完成此操作。 http://www.gnu.org/software/wget/

回答by Jay Riggs

What FTP client software are you using? Is it scriptable? If so, create a script that downloads files and call this script from your batch file.

你用的是什么FTP客户端软件?是否可以编写脚本?如果是这样,请创建一个下载文件的脚本并从您的批处理文件中调用该脚本。

I'm doing this with WS_FTP.

我正在用 WS_FTP 做这个。