PDA

View Full Version : Need an automated FTP batch process?



Paul
04-20-2009, 03:05 PM
I just wrote a quit batch for something and figured it would make a good tutorial or quick refresher for anyone wanting to know dos commands or how to automate a ftp download/delete in command line. Many FTP clients will allow you to automate downloads using a synch process but it is hard to find one that will automate deletion. I needed to download a daily file and delete it after i was done while being able to log everything. Here you go:

1) first thing you need to do is create a bat file
2) open up notepad, add quoted below and save file w/ .bat exentsion to c:\
3) bat file contains the following

cd c:\
ftp -s:ftp.txt mywebsite.com >> c:\ftp_log.log 2>>&1
cd c:\ = change directory c:\
ftp = ftp command
-s:ftp.txt = run this text file
mywebsite.com = the site i want to ftp into
>> = needed to separate commands
c:\ftp_log.log = the file i want to write to; this will allow me to track my process
2>>%1 = append to file so i can see every time this file runs in one file

4) create ftp.txt file to hold all of our login credentials(see quoted below) and run commands

username
password
cd inbox
mget *
y
mdelete
*
y
close
quit
username = username needed to login
password = password needed to login
cd inbox = change directory to location in ftp needed
mget * = get any file
y = yes (confirmation)
mdelete * = delete any file
y = yes (confirmation)
close = close connection
quit = quit bat

5) Then under Start > Accessories > System Tools > Scheduled tasks you can set the task to run as needed.


Google FTP Commands (http://www.google.com/search?q=ftp+commands) if you need to alter anything - Enjoy!

green91
04-20-2009, 04:09 PM
Nice info, may want to throw a binary in there also depending on what type of files are being retrieved.

Paul
04-20-2009, 04:13 PM
Nice info, may want to throw a binary in there also depending on what type of files are being retrieved.

lol - man i racked my brain for a good minute trying to figure out a way to get my client to work and was like mutha fucka i can do this in dos :doh:

its easy to forget how useful command line can be.