<br><br><div class="gmail_quote">On Fri, Dec 12, 2008 at 2:47 PM, Stefan Schwarzer <span dir="ltr"><<a href="mailto:sschwarzer@sschwarzer.net">sschwarzer@sschwarzer.net</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hi Yvan,<br>
<div class="Ih2E3d"><br>
On 2008-12-12 13:40, Yvan Strahm wrote:<br>
> I get this error:<br>
><br>
> Traceback (most recent call last):<br>
> File "./map_taxo.py", line 186, in ?<br>
> Download_me(ftp,ftp_dir,file,target)<br>
> File "./map_taxo.py", line 95, in Download_me<br>
> host=ftputil.FTPHost(ftp,user,password)<br>
> File "/usr/lib/python2.4/site-packages/ftputil/ftputil.py", line 136,<br>
> in __init__<br>
> self._session = self._make_session()<br>
> File "/usr/lib/python2.4/site-packages/ftputil/ftputil.py", line 174,<br>
> in _make_session<br>
> return ftp_error._try_with_oserror(factory, *args, **kwargs)<br>
> File "/usr/lib/python2.4/site-packages/ftputil/ftp_error.py", line 86,<br>
> in _try_with_oserror<br>
> raise PermanentError(obj)<br>
> ftputil.ftp_error.PermanentError: 530 Sorry, the maximum number clients<br>
> (32) from your host are already connected.<br>
> Debugging info: ftputil 2.2.3, Python 2.4.3 (linux2)<br>
<br>
</div>Does the FTPHost construction here refer to the first in the try<br>
clause or the second in the except clause?</blockquote><div><br>the second one in the except<br> <br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br>
<div class="Ih2E3d"><br>
> I have a list of file s to be downloaded and open/close for every items.<br>
> Is it the correct way of doing it?<br>
><br>
> def Download_me(ftp,ftp_dir,file,target):<br>
> user = 'anonymous'<br>
> password = 'anonymous'<br>
> try:<br>
> print "CONNECTING TO "+ ftp + ftp_dir+file+"\n"<br>
<br>
</div>Which actual values did you use for ftp, ftp_dir, file and<br>
target which caused the exception, if I may ask?<br>
<div class="Ih2E3d"></div></blockquote><div><br> ftp='<a href="http://ftp.genome.jp">ftp.genome.jp</a>'<br> ftp_dir='/pub/kegg/genes/organisms_kaas/'<br> file='dola/'<br> tartget=./eukaryotes/vertebrates/fishes/oryzias_latipes_japanese_medaka_/o.latipes.pep<br>
<br> <br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div class="Ih2E3d"><br>
> host=ftputil.FTPHost(ftp,user,password)<br>
> host.chdir(ftp_dir+file)<br>
<br>
</div>Does ftp_dir contain a trailing slash here? I'd recommend to use<br>
FTPHost.path.join(ftp_dir, file) and ftp_dir without a trailing<br>
slash.<br>
<div class="Ih2E3d"></div></blockquote><div><br>sorry I don't use the path.join.function, I should have read the documentation more seriously ... <br><br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div class="Ih2E3d"><br>
> names=host.listdir(host.curdir)<br>
> for name in names:<br>
> if host.path.isfile(name):<br>
> p="pep"<br>
> m_pep=re.search(p,name)<br>
> if m_pep:<br>
> returned=name<br>
> host.download_if_newer(name,target,'b')<br>
> host.close()<br>
> except:<br>
<br>
</div>I suggest you avoid a bare "except"; use "except<br>
ftp_error.PermanentError" (or rather the exceptions you actually<br>
expect). In your current code, _any_ exception would trigger the<br>
except clause, thus catching exceptions you perhaps don't want to<br>
be caught.<br>
<div class="Ih2E3d"><br>
> print "could not be dowloaded try KAAS"<br>
</div>> ftp='<a href="http://ftp.genome.jp" target="_blank">ftp.genome.jp</a> <<a href="http://ftp.genome.jp" target="_blank">http://ftp.genome.jp</a>>'<br>
<br>
If you use this for the host argument of the FTPHost constructor,<br>
it will probably fail. Use just the full name of the FTP server<br>
(<a href="http://ftp.genome.jp" target="_blank">ftp.genome.jp</a>), without the part in angle brackets.<br>
<div class="Ih2E3d"><br>
> ftp_dir='/pub/kegg/genes/organisms_kaas/'<br>
> print "CONNECTING TO "+ ftp + ftp_dir+file+"\n"<br>
> host=ftputil.FTPHost(ftp,user,password)<br>
> host.chdir(ftp_dir+file)<br>
> names=host.listdir(host.curdir)<br>
> for name in names:<br>
> if host.path.isfile(name):<br>
> p="pep"<br>
> m_pep=re.search(p,name)<br>
> if m_pep:<br>
> returned=name<br>
> host.download_if_newer(name,target,'b')<br>
> host.close()<br>
<br>
</div>Possibly you should put the common parts of the try and except<br>
clauses into a function.<br>
<br>
Regarding the symmetry of the FTPHost construction and calling<br>
the close method, at first sight this looks well. However, if the<br>
constructor fails, the close method won't be called, so that may<br>
be the reason why you exhaust the possible number of connections.<br>
(On the other hand, this could be a genuine error message if<br>
enough people are logged into the FTP server at the same time.)<br>
I think you should use a try ... finally construct:<br>
<div class="Ih2E3d"><br>
try:<br>
print "CONNECTING TO "+ ftp + ftp_dir+file+"\n"<br>
host=ftputil.FTPHost(ftp,user,password)<br>
</div> try:<br>
<div class="Ih2E3d"> host.chdir(ftp_dir+file)<br>
names=host.listdir(host.curdir)<br>
for name in names:<br>
if host.path.isfile(name):<br>
p="pep"<br>
m_pep=re.search(p,name)<br>
if m_pep:<br>
returned=name<br>
host.download_if_newer(name,target,'b')<br>
</div> finally:<br>
host.close()<br>
except:<br>
...<br>
<br>
In this way, the connection will be closed, whether there's an<br>
exception or not.<br>
</blockquote><div><br><br>Thanks I will try to change the code with all your recommendations.<br>Thanks a lot for your help and tips <br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br>
Does that help?<br>
</blockquote><div><br>yes a lot. <br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><br>
Best regards,<br>
Stefan<br>
_______________________________________________<br>
ftputil mailing list<br>
<a href="mailto:ftputil@codespeak.net">ftputil@codespeak.net</a><br>
<a href="http://codespeak.net/mailman/listinfo/ftputil" target="_blank">http://codespeak.net/mailman/listinfo/ftputil</a><br>
</blockquote></div><br><br>Have a nice week end<br>Best Regards,<br>yvan<br>