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!
Copy latest file from ftp site every day
Moderator: DosItHelp
Re: Copy latest file from ftp site every day
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.FtpBatchDownloadOnlyNewFiles
Regards
aGerman
Wat about http://www.dostips.com/DtTipsFtpBatchScript.php#Batch.FtpBatchDownloadOnlyNewFiles
Regards
aGerman
-
- Posts: 319
- Joined: 12 May 2006 01:13
Re: Copy latest file from ftp site every day
Use a programming language with FTP support to do file transfer. eg in Python
usage:
Code: 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:
Code: Select all
c:\test> python myftp.py
Re: Copy latest file from ftp site every day
aGerman,
Thanks so much! This worked perfectly!
Cheers
Thanks so much! This worked perfectly!
Cheers