a question about my script

alper soyler alpersoyler at yahoo.com
Thu Aug 31 09:01:09 EDT 2006


Hi,

I changed the script as you wrote below:

from ftplib import FTP

def handleDownload(block):
    file.write(block)
    print ".",
 
ftp = FTP('ftp.genome.jp')

 
print ftp.login()
 
directory = 'pub/kegg/genomes'
ftp.cwd(directory)

k=0
for direct in ftp.nlst():
    curdir = '%s/%s' % (directory, direct)
    ftp.cwd(curdir)
    for filename in ftp.nlst():
        if not filename.endswith('.pep'): continue
        file = open(filename, 'wb')
        ftp.retrbinary('RETR %s/%s' % (curdir, filename), handleDownload)
        file.close()
    k=k+1    

print ftp.close()

However, it gave the same error message:

230 Anonymous access granted, restrictions apply.
Traceback (most recent call last):
  File "ftp1.0.py", line 18, in ?
    ftp.cwd(curdir)
  File "/usr/lib/python2.4/ftplib.py", line 494, in cwd
    return self.voidcmd(cmd)
  File "/usr/lib/python2.4/ftplib.py", line 246, in voidcmd
    return self.voidresp()
  File "/usr/lib/python2.4/ftplib.py", line 221, in voidresp
    resp = self.getresp()
  File "/usr/lib/python2.4/ftplib.py", line 216, in getresp
    raise error_perm, resp
ftplib.error_perm: 550 pub/kegg/genomes/aae: No such file or directory

However, in ftp.genome.jp/pub/kegg/genomes/  site, there is 'aae' directory. What can be the reason?

regards,
alper

----- Original Message ----
From: Gabriel Genellina <gagsl-py at yahoo.com.ar>
To: alper soyler <alpersoyler at yahoo.com>
Cc: Python-list at python.org
Sent: Tuesday, August 29, 2006 10:26:57 AM
Subject: Re: a question about my script

At Tuesday 29/8/2006 03:55, alper soyler wrote:

>I am trying to get some files from an ftp site by ftplib module and 
>I wrote the below script. However I have a problem. With my script, 
>I login to ftp.genome.jp site. then, I am changing the directory to 
>pub/kegg/genomes/afm and I am downloading "a.fumigatus.pep" file. 
>However, what I want is to connect pub/kegg/genomes directory and in 
>this directory there are 3 letters name files

3 letters *files*? or 3 letters *directories*?

>e.g. 'afm' and in each of these 3 letters files there is a file with 
>the extension of '.pep' like a.fumigatus.pep. I want to get these 
>'.pep' files from the 3 letter named files. If you help me I will be 
>very glad. Thanks you in advance.

Do a cwd() starting one level above (that is, pub/kegg/genomes); 
using ftp.dir() you can get the subdirectories, then iterate over all 
of them, using another dir() to find the .pep files needed.

>directory = 'pub/kegg/genomes/ afm'

Is that whitespace intentional?

(If you just want to download the files and don't need really a 
Python script, try wget...)



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





-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20060831/51c6c24e/attachment.html>


More information about the Python-list mailing list