<br><br><div class="gmail_quote">On Fri, Dec 12, 2008 at 2:47 PM, Stefan Schwarzer <span dir="ltr">&lt;<a href="mailto:sschwarzer@sschwarzer.net">sschwarzer@sschwarzer.net</a>&gt;</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>
&gt; I get this error:<br>
&gt;<br>
&gt; Traceback (most recent call last):<br>
&gt; &nbsp; File &quot;./map_taxo.py&quot;, line 186, in ?<br>
&gt; &nbsp; &nbsp; Download_me(ftp,ftp_dir,file,target)<br>
&gt; &nbsp; File &quot;./map_taxo.py&quot;, line 95, in Download_me<br>
&gt; &nbsp; &nbsp; host=ftputil.FTPHost(ftp,user,password)<br>
&gt; &nbsp; File &quot;/usr/lib/python2.4/site-packages/ftputil/ftputil.py&quot;, line 136,<br>
&gt; in __init__<br>
&gt; &nbsp; &nbsp; self._session = self._make_session()<br>
&gt; &nbsp; File &quot;/usr/lib/python2.4/site-packages/ftputil/ftputil.py&quot;, line 174,<br>
&gt; in _make_session<br>
&gt; &nbsp; &nbsp; return ftp_error._try_with_oserror(factory, *args, **kwargs)<br>
&gt; &nbsp; File &quot;/usr/lib/python2.4/site-packages/ftputil/ftp_error.py&quot;, line 86,<br>
&gt; in _try_with_oserror<br>
&gt; &nbsp; &nbsp; raise PermanentError(obj)<br>
&gt; ftputil.ftp_error.PermanentError: 530 Sorry, the maximum number clients<br>
&gt; (32) from your host are already connected.<br>
&gt; 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>&nbsp;<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>
&gt; I have a list of file s to be downloaded and open/close for every items.<br>
&gt; Is it the correct way of doing it?<br>
&gt;<br>
&gt; def Download_me(ftp,ftp_dir,file,target):<br>
&gt; &nbsp; user = &#39;anonymous&#39;<br>
&gt; &nbsp; password = &#39;anonymous&#39;<br>
&gt; &nbsp; try:<br>
&gt; &nbsp; &nbsp; print &quot;CONNECTING TO &quot;+ ftp + ftp_dir+file+&quot;\n&quot;<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>&nbsp;&nbsp;&nbsp; ftp=&#39;<a href="http://ftp.genome.jp">ftp.genome.jp</a>&#39;<br>&nbsp;&nbsp;&nbsp; ftp_dir=&#39;/pub/kegg/genes/organisms_kaas/&#39;<br>&nbsp;&nbsp;&nbsp; file=&#39;dola/&#39;<br>&nbsp;&nbsp;&nbsp; tartget=./eukaryotes/vertebrates/fishes/oryzias_latipes_japanese_medaka_/o.latipes.pep<br>
<br>&nbsp;<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>
&gt; &nbsp; &nbsp; host=ftputil.FTPHost(ftp,user,password)<br>
&gt; &nbsp; &nbsp; host.chdir(ftp_dir+file)<br>
<br>
</div>Does ftp_dir contain a trailing slash here? I&#39;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&#39;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>
&gt; &nbsp; &nbsp; names=host.listdir(host.curdir)<br>
&gt; &nbsp; &nbsp; for name in names:<br>
&gt; &nbsp; &nbsp; &nbsp; if host.path.isfile(name):<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; p=&quot;pep&quot;<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; m_pep=re.search(p,name)<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; if m_pep:<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; returned=name<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; host.download_if_newer(name,target,&#39;b&#39;)<br>
&gt; &nbsp; &nbsp; host.close()<br>
&gt; &nbsp; except:<br>
<br>
</div>I suggest you avoid a bare &quot;except&quot;; use &quot;except<br>
ftp_error.PermanentError&quot; (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&#39;t want to<br>
be caught.<br>
<div class="Ih2E3d"><br>
&gt; &nbsp; &nbsp; print &quot;could not be dowloaded try KAAS&quot;<br>
</div>&gt; &nbsp; &nbsp; ftp=&#39;<a href="http://ftp.genome.jp" target="_blank">ftp.genome.jp</a> &lt;<a href="http://ftp.genome.jp" target="_blank">http://ftp.genome.jp</a>&gt;&#39;<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>
&gt; &nbsp; &nbsp; ftp_dir=&#39;/pub/kegg/genes/organisms_kaas/&#39;<br>
&gt; &nbsp; &nbsp; print &quot;CONNECTING TO &quot;+ ftp + ftp_dir+file+&quot;\n&quot;<br>
&gt; &nbsp; &nbsp; host=ftputil.FTPHost(ftp,user,password)<br>
&gt; &nbsp; &nbsp; host.chdir(ftp_dir+file)<br>
&gt; &nbsp; &nbsp; names=host.listdir(host.curdir)<br>
&gt; &nbsp; &nbsp; for name in names:<br>
&gt; &nbsp; &nbsp; &nbsp; if host.path.isfile(name):<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; p=&quot;pep&quot;<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; m_pep=re.search(p,name)<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; if m_pep:<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; returned=name<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; host.download_if_newer(name,target,&#39;b&#39;)<br>
&gt; &nbsp; &nbsp; 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&#39;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>
 &nbsp; &nbsp;print &quot;CONNECTING TO &quot;+ ftp + ftp_dir+file+&quot;\n&quot;<br>
 &nbsp; &nbsp;host=ftputil.FTPHost(ftp,user,password)<br>
</div> &nbsp; &nbsp;try:<br>
<div class="Ih2E3d"> &nbsp; &nbsp; &nbsp; &nbsp;host.chdir(ftp_dir+file)<br>
 &nbsp; &nbsp; &nbsp; &nbsp;names=host.listdir(host.curdir)<br>
 &nbsp; &nbsp; &nbsp; &nbsp;for name in names:<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if host.path.isfile(name):<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;p=&quot;pep&quot;<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;m_pep=re.search(p,name)<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if m_pep:<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;returned=name<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;host.download_if_newer(name,target,&#39;b&#39;)<br>
</div> &nbsp; &nbsp;finally:<br>
 &nbsp; &nbsp; &nbsp; &nbsp;host.close()<br>
except:<br>
 &nbsp; &nbsp;...<br>
<br>
In this way, the connection will be closed, whether there&#39;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>