开发者

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

开发者 https://www.devze.com 2022-12-30 16: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) an

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)


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

  • http://www.howtogeek.com/howto/windows/how-to-automate-ftp-uploads-from-the-windows-command-line/

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


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


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号