How to create a .BAT file to download file from HT

2019-06-18 07:56发布

How to create a .BAT file to download file or folder from FTP server? (and replace with it existing file) (we have links like ftp://me:mypass@example.com/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)

4条回答
\"骚年 ilove
2楼-- · 2019-06-18 08:35

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

The example is about uploading, but the principle is the same (just use get instead of 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.

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
查看更多
爷、活的狠高调
3楼-- · 2019-06-18 08:36

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:

ftp -s:download.scr
查看更多
一纸荒年 Trace。
4楼-- · 2019-06-18 08:37

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.

I'm doing this with WS_FTP.

查看更多
老娘就宠你
5楼-- · 2019-06-18 08:43

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

查看更多
登录 后发表回答