get todays files

Tim Chase python.list at tim.thechases.com
Thu Dec 11 13:57:18 EST 2008


> I know this will sound like I am being very cheeky, but is there a way 
> you can make this for where the ftp server is actually windows server?

For Windows Server, I don't have a Windows FTP server to test 
with -- I've got the company Linux server, and the previous 
testing site I used (I think I used ftp.mozilla.org) which also 
likely runs some flavor of Linux.  Neither supports the NLST from 
my testing.

> curr_date = strftime("%d %B %Y", gmtime())

The first thing I noticed was that your strftime formating needs 
to match the format of the date that comes back from the FTP 
site.  In my test, that was "YYYYMMDD".  As such, your "%d %B %Y" 
would likely need to be "%Y%m%d".

>     ftp.retrlines('NLST',makelist)

The servers I tried didn't support the NLST command so I can't 
exactly follow along here.  However assuming that it correctly 
populates the list of files here

>     for ff in files:

correctly, that's immaterial to me.

>         ftp = FTP(ftp_server)
>         ftp.set_pasv(False)
>         resp = ftp.login(ftp_uname,ftp_pwd)

Just curious why you're logging into the server each pass through 
the loop -- I'd just connect once at the beginning of the loop, 
pull the files, and then disconnect at the end of the loop.

>         assert code == "213", "Unexpected result"

Does this assert fail at any point?

>         if stamp[:8] == today:

Given the above date-formatting, this should fail *every* time 
unless your FTP server is returning the date in some format other 
than "YYYYMMDDhhmmss"



It's hard to pinpoint actual problems as this block of code has 
been modified, or doesn't run...there's some bogus indentation in 
your post:

>                     log('Transferring: ' + ff[0])
>                 # make parameters to wget the backup file
>                 params = ' ftp://' + ftp_server + '/' + ff[0]
>                 rcode = subprocess.call('c:/wget.exe ' + params)
>                 log('Return code from wget = ' + str(rcode))
>                 if (rcode == 0):
>              ff[1] = 1
>        
>             else:
>                 log('File ' + ff[0] + ' already exists locally, not 
> transferring')

because this "else" is hanging oddly.  Additionally, the FTP 
object has methods for downloading the content of a file, so I'd 
not bother shelling out to wget as an additional dependency.

-tkc







More information about the Python-list mailing list