Copy files from FTP server to local directory?

52,787

Solution 1

To program ftp from a batch file, see http://support.microsoft.com/kb/96269. You need to call ftp like this

ftp -i -s:ftpcommands.txt

where ftpcommands.txt looks something like this:

open ftp.myftpsite.com
username
password
bin
cd out
mget *
del *
bye

For running this every 15 minutes, see other replies (at or Command Scheduler).

(The -i parameter is to turn off interactive prompting - the other way to do this is to add a prompt off command to the commands text file before the mget. Without this, mget will stop and ask you to confirm before getting each file. [Thanks to Adriano for pointing this out!])

Solution 2

The accepted answer by @AAT suggests using Windows built-in ftp.exe command-line client. While that can work, more often it won't, because this client does support FTP active mode only, which does not play nicely with today's ubiquitous firewalls and NATs. It also does not support encrypted FTPS (FTP over TLS/SSL).

If you have a problem with the above, you need to use a 3rd party FTP client. Most of them do support both the passive mode and encryption.


For example with WinSCP FTP client, you can use the following batch file (.bat):

WinSCP.com /command ^
    "open ftp://username:[email protected]/" ^
    "get /out/* c:\local\path\" ^
    "exit"

In case you already have an ftp.exe script, there's a guide for converting it to WinSCP script.


For the scheduling part, see the guide to scheduling transfers to FTP server.


(I'm the author of WinSCP)

Share:
52,787
oopbase
Author by

oopbase

C# .NET developer, F# enthusiast and impassionate pianist

Updated on March 23, 2021

Comments

  • oopbase
    oopbase about 3 years

    I want to create a batch file in Windows Server, including the following functions:

    • Connection to a FTP server
    • Copying the files from there (directory called "out") to a local directory
    • if success, then deleting the files from the FTP server
    • repeating those steps every 15 minutes

    I haven't done that much with batch files so far, so it would be great if you could help me. I know there is the ftp command, and I know how to connect (ftp open), but unfortunately I don't know how to copy those files from there every 15 minutes.

    Thanks a lot for your help!