diff sra_fetch.py @ 7:d7708f338c82 draft

bug fixes
author Matthew Shirley <mdshw5@gmail.com>
date Wed, 14 Nov 2012 16:55:51 -0500
parents f74bbb22bf62
children
line wrap: on
line diff
--- a/sra_fetch.py	Wed Nov 14 13:36:21 2012 -0500
+++ b/sra_fetch.py	Wed Nov 14 16:55:51 2012 -0500
@@ -12,12 +12,19 @@
 ftp = FTP('ftp-trace.ncbi.nih.gov')
 
 # Open file and transfer requested SRA as a file
+# Try to change the working directory until it works
 sra = open(outfile, 'wb')
 ftp.login('ftp')
-ftp.cwd('/sra/sra-instant/reads/ByRun/sra/' + 
-        prefix + '/' +
-        prefix + middle + '/' +
-        prefix + middle + suffix + '/')
-ftp.pwd()
+connected = False
+while not connected:
+    try:
+        ftp.cwd('/sra/sra-instant/reads/ByRun/sra/' + 
+                prefix + '/' +
+                prefix + middle + '/' +
+                prefix + middle + suffix + '/')
+        connected = True
+    except:
+        pass
+        
 ftp.retrbinary('RETR ' + prefix + middle + suffix + '.sra', sra.write)
 ftp.quit()