Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Copy files from FTP server to local directory?

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!

like image 383
oopbase Avatar asked Feb 21 '11 09:02

oopbase


People also ask

How do I copy multiple files from an FTP site?

To copy multiple files at once, use the mput command. You can supply a series of individual file names and you can use wildcard characters. The mput command copies each file individually, asking you for confirmation each time. To close the ftp connection, type bye .

How do I transfer files from FTP to local directory?

Alternatively, type FTP and press Enter at the command prompt in Windows. From here, use the open command to connect to the server. Once you login, it takes you to the default directory. You can move to the one where you want to copy files to, and open it using the command.


1 Answers

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!])

like image 177
AAT Avatar answered Sep 23 '22 14:09

AAT