tags:

views:

231

answers:

4

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:[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)

+1  A: 

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

JM
+1  A: 

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.

Jay Riggs
+2  A: 

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
Heinzi
So... grate how to replace existing file with recived file? Could you add code example, please.
Blender
Added an example.
Heinzi
+1  A: 

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
ewall
So... grate how to replace existing file with recived file? Could you add code example, please.
Blender
Heinzi's example code should work :)
ewall