I have a similar problem. I need to download the same file every hour so it will be nice to be able to rename the downloads with a variable name.
For example in this case: from ftplib import FTP ftp=FTP('tgftp.nws.noaa.gov') ftp.login() ftp.cwd('SL.us008001/DF.of/DC.radar/DS.81dpr/SI.kbuf') ftp.retrbinar('RETR sn.last', open('sn','wb').write) ftp.quit() Question: How to achive rename the downloaded files as sn1, sn2, sn3.... or with a timestamp? The ftp.rename() is used to rename files on the server, isn't it?I'm Python shy. Please help. Any suggestion will be appreciated. On Jul 28, 11:41 am, MRAB <[EMAIL PROTECTED]> wrote: > On Jul 28, 2:27 pm, "Harry" <[EMAIL PROTECTED]> wrote: > > > Hi there. I am trying to download a file(sn.last) from a public FTP > > server with the following code: > > > from ftplib import FTP > > ftp=FTP('tgftp.nws.noaa.gov') > > ftp.login() > > ftp.cwd('SL.us008001/DF.of/DC.radar/DS.81dpr/SI.kbuf') > > ftp.retrbinar('RETR sn.last', open(mydpa,'wb').write) > > open(mydpa,'wb') would open the file to which you're saving the data, > but you haven't defined to mydpa, so Python will complain. > > > ftp.quit() > > > but got an error message, which I think is normal: > > > Traceback (most recent call last): > > File "<pyshell#13>", line 1, in <module> > > ftp.retrbinary('RETR sn.last', open(mydpa,'wb').write) > > NameError: name 'mydpa' is not defined > > Yep! > > > > > I don't know much about python, but just try to use the code to > > download data. I don't know where the file will be saved to. Is the > > mydata a file name or a folder name? where will it be saved to even > > if it's working? Please help be fixed the problem step by step? I am > > using 2.5.2 by the way. > > You need to tell it where to save the data by defining mydpa. > > > > > I really appreciate your help. Thanks.- Hide quoted text - > > - Show quoted text - -- http://mail.python.org/mailman/listinfo/python-list