Page 1 of 1
Copy latest file from ftp site every day
Posted: 13 Sep 2010 15:22
by kobys
I'm trying to write a batch file that goes to an ftp site, gets the last updated file and copies it to a directory on my network every day. Is there an easy way to do this. The last file is always the last business day if there is no way to specify the last updated file in a generic fashion.
Thanks for any help!
Re: Copy latest file from ftp site every day
Posted: 13 Sep 2010 15:42
by aGerman
I'm not familar with ftp because I never used it by myself, but here on DosTips you'll find some example scripts.
Wat about
http://www.dostips.com/DtTipsFtpBatchScript.php#Batch.FtpBatchDownloadOnlyNewFilesRegards
aGerman
Re: Copy latest file from ftp site every day
Posted: 13 Sep 2010 19:53
by ghostmachine4
Use a programming language with FTP support to do file transfer. eg in
PythonCode: Select all
import ftplib
server="localhost"
user="anonymous"
password="test@email.com"
filelist=[]
def download(ftp, filename):
ftp.retrbinary("RETR " + filename, open(filename,"wb").write)
try:
ftp = ftplib.FTP()
ftp.debug(3)
ftp.connect(server,21)
ftp.login(user,password)
except Exception,e:
print e
else:
ftp.cwd("directory to change if any")
ftp.retrlines('LIST',filelist.append)
for latest in filelist:
if latest.startswith("-") and "latest file pattern if any" in latest:
print latest
download(ftp,latest)
ftp.quit()
sys.exit()
usage:
Re: Copy latest file from ftp site every day
Posted: 14 Sep 2010 07:41
by kobys
aGerman,
Thanks so much! This worked perfectly!
Cheers