There was a trick in your code I had never seen before. The comma was necessary to create a sequence here:<br>&nbsp;<br>&nbsp; &gt;&gt;&gt; t = threading.Thread(target=poll, args=(host,))<br><br>Anyway, the program seems to head once I initiate the thread. I created a class for your code and then called it like below. I think throwing a simple chdir() in between each downloaded file should prevent the timeout, but I'd like to see if I can get the thread thing working anyway:
<br><br>import ftputil <br>import time <br>import threading <br>&nbsp;<br>class busyloop(object): <br>&nbsp;<br>&nbsp;&nbsp;&nbsp; def __init__(self,host): <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.host = host <br>&nbsp;<br>&nbsp;&nbsp;&nbsp; def poll(self, host): <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; while True: <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; host.chdir(host.curdir) <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; time.sleep(300) <br>&nbsp;<br>&nbsp;&nbsp;&nbsp; def loop(self): <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; t = threading.Thread(target=self.poll, args=(self.host,)) <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; t.start() <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; t.join() <br><br><br>
&nbsp;&nbsp;&nbsp; def fetch_file(my): <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #print &quot;host = ftputil.FTPHost&quot;,&nbsp; my.cnf.dl.host, my.cnf.dl.user,&nbsp; my.c\<br>nf.dl.password <br>&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; host = ftputil.FTPHost(my.cnf.dl.host, my.cnf.dl.user, <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
my.cnf.dl.password) <br>&nbsp;<br>#&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; t = data.localpy.ftputil.busyloop(host) <br>#&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; t.loop() <br>&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print host <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; host.chdir(my.cnf.dl.root_cwd) <br>&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; expected_files = ['diseasecategories_export.txt', 
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'fdadruglistings_export.txt', <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'medicalareas_export.txt', <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'pipelinedrugs_export.txt', <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'pipelinedrugscategories_export.txt', <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'studylistings_export.txt', 
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'studyresults_export.txt'] <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for f in host.listdir(host.curdir): <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if re.compile(my.cnf.dl.filepattern).search(f): <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print &quot;Downloading&quot;, f <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
host.chdir(host.curdir) <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; host.download(f, f, 't') <br>&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; try: <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; expected_files.remove(path(f).basename()) <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; except: <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pass 
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; shutil.copy(f, my.storage.input) <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; shutil.move(f, my.storage.zip) <br>&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if len(expected_files) != 0: <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print &quot;Expected files&quot;, expected_files, &quot;not on&quot;, 
my.cnf.dl.host <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sys.exit() <br><br><br><div><span class="gmail_quote">On 12/5/06, <b class="gmail_sendername">Stefan Schwarzer</b> &lt;<a href="mailto:sschwarzer@sschwarzer.net">sschwarzer@sschwarzer.net</a>
&gt; wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Hi Terrence,<br><br>On 2006-12-05 17:25, Terrence Brannon wrote:<br>&gt; Hi, I filled out the subscription form at GMANE for this list so that it
<br>&gt; will be archived there as well as mail-archive.com... it is not easy to<br>&gt; search mailman archives.<br><br>You are quite right, thanks for adding the Gmane interface for<br>the mailing list!<br><br>&gt; Anyway, I have an issue where I am downloading some large files from a
<br>&gt; server and I am getting at &quot;Connection timed out&quot; error.<br><br>Do you get the error _during_ the download or after using the<br>FTPHost object _after_ the download?<br><br>I assume the latter. Ftputil opens an FTP session for the &quot;main&quot;
<br>session when you construct an FTPHost object. For each file-like<br>object (i. e. also for up/downloads) a new FTP session is opened<br>behind the scenes. So I guess that after the download your main<br>session has timed out.
<br><br>You could prevent this by giving the main session something to do<br>during the download. If your Python is compiled with threading<br>support, the following should work:<br><br>&gt;&gt;&gt; import ftputil<br>&gt;&gt;&gt; import time
<br>&gt;&gt;&gt; import threading<br>&gt;&gt;&gt;<br>&gt;&gt;&gt; def poll(host):<br>...&nbsp;&nbsp; while True:<br>...&nbsp;&nbsp;&nbsp;&nbsp; # getcwd won't work because it only fetches a cached value<br>...&nbsp;&nbsp;&nbsp;&nbsp; host.chdir(host.curdir)<br>...&nbsp;&nbsp;&nbsp;&nbsp; # must be less seconds than a server timeout
<br>...&nbsp;&nbsp;&nbsp;&nbsp; time.sleep(300)<br>...<br>&gt;&gt;&gt; host = ftputil.FTPHost(&quot;<a href="http://ftp.debian.org">ftp.debian.org</a>&quot;, 'anonymous',<br>...&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'<a href="mailto:sschwarzer@sschwarzer.net">
sschwarzer@sschwarzer.net</a>')`<br>&gt;&gt;&gt; t = threading.Thread(target=poll, args=(host,))<br>&gt;&gt;&gt; t.start()<br>&gt;&gt;&gt; t.join()<br><br>This isn't production-ready code (e. g. the thread isn't stopped<br>
when the FTPHost instance is closed). Also note that server<br>timeouts are there for a reason, so be very careful about the<br>duration you maintain the connection.<br><br>Please let me know if that helps.<br><br>I had thought about &quot;timeout safety&quot; a while ago, see
<br><a href="http://codespeak.net/pipermail/ftputil/2006q1/000073.html">http://codespeak.net/pipermail/ftputil/2006q1/000073.html</a> . Since<br>I didn't get any responses, I removed the timeout functionality<br>in the face of the described implementation difficulty.
<br><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">http://codespeak.net/mailman/listinfo/ftputil
</a><br></blockquote></div><br>