Im pretty new to python so im still finding my feet..
Ive written a small ftp program that downloads a file but its quite basic in that it gets the last element from the list and then downloads it.
What is the easiest way to add some logic so it only downloads the latest file if it is a .jpa extenstion and it is the newest file within the list ....
The code is :
#!/usr/bin/python
#### IMPORT MODULES ####
import ftplib
import string
import os
#### DEFINE VARIABLES ####
ftpserver = "??????????"
username = "??????????"
password = "??????????"
localdir = "??????????"
#### SET EMPTY LIST ####
data = []
#### CHANGE LOCAL DIRECTORY #####
os.chdir(localdir)
#### CONNECT TO FTP SERVER ####
ftp = ftplib.FTP(ftpserver)
ftp.login(username, password)
#### GET LIST OF FILES ####
ftp.dir(data.append)
#### GET LAST FILENAME ####
data1 = data[-1:]
data2 = "".join(data1)
data3 = data2.split()
data4 = data3[-1:]
dstfile = "".join(data4)
#### DOWNLOAD FILE ####
try:
ftp.retrbinary('RETR '+dstfile, open(dstfile, 'wb').write)
except Error:
print "Error transfering", dstfile
#### GRACEFULLY CLOSE FTP CONNECTION ####
ftp.close()
ftp.quit()
Thanks,