At Friday 1/9/2006 06:32, alper soyler wrote:

Thank you very much for your help. The program works however, after downloading 121 '.pep' files, it gave me time out error:

Traceback (most recent call last):
  File "ftp1.0.py", line 18, in ?
    for filename in ftp.nlst():
  ...
  File "/usr/lib/python2.4/ftplib.py", line 324, in ntransfercmd
    conn.connect(sa)
  File "<string>", line 1, in connect
socket.error: (110, 'Connection timed out')

How can I continue from the last download or is there any way to arrange the time? Thank you very much.

You can change the default timeout for sockets with socket.setdefaulttimeout(secs) (this is a module function; call it at the beginning of your script). To continue from the last download, you could skip downloading files when they already exist on your disk: before opening it for write, use os.path.exists(full_filename) to detect it, and skip the download part.

If you want to continue even after an exception happens, use the try/except syntax.
I don't have your code at hand to show the details, but it was something like:

for directory in dirlist:
    cwd(directory)
    for filename in directory:
        download file

You may want to change it to:

for directory in dirlist:
    try:
      cwd(directory)
      for filename in directory:
        if (filename already exists): continue
        try:
          download file
        except: print '%s: %s' % sys.exc_info()[:2]
    except: print '%s: %s' % sys.exc_info()[:2]

This way, if an error happens within downloading a file, goes on the next; and if an error happens procesing a directory, goes on the next too. As a general guide, bare except clauses (that is, without a matching exception class) are not good, but for an utility script like yours I think it's fine.


Gabriel Genellina
Softlab SRL

        
        
                
__________________________________________________
Preguntá. Respondé. Descubrí.
Todo lo que querías saber, y lo que ni imaginabas,
está en Yahoo! Respuestas (Beta).
¡Probalo ya! http://www.yahoo.com.ar/respuestas

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to