4545# FTP Support
4646ftpssl = True
4747try :
48- from ftplib import FTP , FTP_TLS
48+ from ftplib import FTP , FTP_TLS , all_errors
4949except ImportError :
5050 ftpssl = False
51- from ftplib import FTP
51+ from ftplib import FTP , all_errors
5252
5353try :
5454 import ujson as json
@@ -389,7 +389,7 @@ def decode_unicode_escape(value):
389389__version_date__ = str (__version_date_info__ [0 ]) + "." + str (
390390 __version_date_info__ [1 ]).zfill (2 ) + "." + str (__version_date_info__ [2 ]).zfill (2 )
391391__revision__ = __version_info__ [3 ]
392- __revision_id__ = "$Id$"
392+ __revision_id__ = "$Id: 9911cc0b37bf3b39652ce61ec29c1e2180f46e43 $"
393393if (__version_info__ [4 ] is not None ):
394394 __version_date_plusrc__ = __version_date__ + \
395395 "-" + str (__version_date_info__ [4 ])
@@ -9402,19 +9402,39 @@ def download_file_from_ftp_file(url):
94029402 log .info ("Error With URL " + url )
94039403 return False
94049404 ftp .login (urlparts .username , urlparts .password )
9405- if (urlparts .scheme == "ftps" ):
9405+ if (urlparts .scheme == "ftps" or isinstance ( ftp , FTP_TLS ) ):
94069406 ftp .prot_p ()
9407+ # Try EPSV first, then fall back
9408+ try :
9409+ ftp .sendcmd ("EPSV" ) # request extended passive
9410+ ftp .retrlines ("LIST" , callback = lambda line : None )
9411+ except all_errors :
9412+ try :
9413+ ftp .set_pasv (True )
9414+ ftp .retrlines ("LIST" , callback = lambda line : None )
9415+ except all_errors :
9416+ ftp .set_pasv (False )
9417+ ftp .retrlines ("LIST" , callback = lambda line : None )
94079418 ftpfile = MkTempFile ()
94089419 ftp .retrbinary ("RETR " + urlparts .path , ftpfile .write )
9409- #ftp.storbinary("STOR "+urlparts.path, ftpfile.write);
94109420 ftp .close ()
94119421 ftpfile .seek (0 , 0 )
94129422 return ftpfile
94139423
94149424
9425+ def download_file_from_ftps_file (url ):
9426+ return download_file_from_ftp_file (url )
9427+
9428+
94159429def download_file_from_ftp_string (url ):
94169430 ftpfile = download_file_from_ftp_file (url )
9417- return ftpfile .read ()
9431+ ftpout = ftpfile .read ()
9432+ ftpfile .close ()
9433+ return ftpout
9434+
9435+
9436+ def download_file_from_ftps_string (url ):
9437+ return download_file_from_ftp_string (url )
94189438
94199439
94209440def upload_file_to_ftp_file (ftpfile , url ):
@@ -9456,21 +9476,40 @@ def upload_file_to_ftp_file(ftpfile, url):
94569476 log .info ("Error With URL " + url )
94579477 return False
94589478 ftp .login (urlparts .username , urlparts .password )
9459- if (urlparts .scheme == "ftps" ):
9479+ if (urlparts .scheme == "ftps" or isinstance ( ftp , FTP_TLS ) ):
94609480 ftp .prot_p ()
9481+ # Try EPSV first, then fall back
9482+ try :
9483+ ftp .sendcmd ("EPSV" ) # request extended passive
9484+ ftp .retrlines ("LIST" , callback = lambda line : None )
9485+ except all_errors :
9486+ try :
9487+ ftp .set_pasv (True )
9488+ ftp .retrlines ("LIST" , callback = lambda line : None )
9489+ except all_errors :
9490+ ftp .set_pasv (False )
9491+ ftp .retrlines ("LIST" , callback = lambda line : None )
94619492 ftp .storbinary ("STOR " + urlparts .path , ftpfile )
94629493 ftp .close ()
94639494 ftpfile .seek (0 , 0 )
94649495 return ftpfile
94659496
94669497
9498+ def upload_file_to_ftps_file (ftpfile , url ):
9499+ return upload_file_to_ftp_file (ftpfile , url )
9500+
9501+
94679502def upload_file_to_ftp_string (ftpstring , url ):
94689503 ftpfileo = MkTempFile (ftpstring )
94699504 ftpfile = upload_file_to_ftp_file (ftpfileo , url )
94709505 ftpfileo .close ()
94719506 return ftpfile
94729507
94739508
9509+ def upload_file_to_ftps_string (ftpstring , url ):
9510+ return upload_file_to_ftp_string (ftpstring , url )
9511+
9512+
94749513class RawIteratorWrapper :
94759514 def __init__ (self , iterator ):
94769515 self .iterator = iterator
@@ -9581,7 +9620,9 @@ def download_file_from_http_file(url, headers=None, usehttp=__use_http_lib__):
95819620
95829621def download_file_from_http_string (url , headers = geturls_headers_pyfile_python_alt , usehttp = __use_http_lib__ ):
95839622 httpfile = download_file_from_http_file (url , headers , usehttp )
9584- return httpfile .read ()
9623+ httpout = httpfile .read ()
9624+ httpfile .close ()
9625+ return httpout
95859626
95869627
95879628if (haveparamiko ):
@@ -9638,7 +9679,9 @@ def download_file_from_sftp_file(url):
96389679if (haveparamiko ):
96399680 def download_file_from_sftp_string (url ):
96409681 sftpfile = download_file_from_sftp_file (url )
9641- return sftpfile .read ()
9682+ sftpout = sftpfile .read ()
9683+ sftpfile .close ()
9684+ return sftpout
96429685else :
96439686 def download_file_from_sftp_string (url ):
96449687 return False
@@ -9754,7 +9797,9 @@ def download_file_from_pysftp_file(url):
97549797if (havepysftp ):
97559798 def download_file_from_pysftp_string (url ):
97569799 sftpfile = download_file_from_pysftp_file (url )
9757- return sftpfile .read ()
9800+ sftpout = sftpfile .read ()
9801+ sftpfile .close ()
9802+ return sftpout
97589803else :
97599804 def download_file_from_pysftp_string (url ):
97609805 return False
@@ -9861,10 +9906,12 @@ def download_file_from_internet_string(url, headers=geturls_headers_pyfile_pytho
98619906def download_file_from_internet_uncompress_string (url , headers = geturls_headers_pyfile_python_alt , formatspecs = __file_format_dict__ ):
98629907 fp = download_file_from_internet_string (url )
98639908 fp = UncompressFileAlt (fp , formatspecs )
9864- fp .seek (0 , 0 )
98659909 if (not fp ):
98669910 return False
9867- return fp
9911+ fp .seek (0 , 0 )
9912+ fpout = fp .read ()
9913+ fp .close
9914+ return fpout
98689915
98699916
98709917def upload_file_to_internet_file (ifp , url ):
@@ -9886,11 +9933,10 @@ def upload_file_to_internet_file(ifp, url):
98869933def upload_file_to_internet_compress_file (ifp , url , compression = "auto" , compressionlevel = None , compressionuselist = compressionlistalt , formatspecs = __file_format_dict__ ):
98879934 fp = CompressOpenFileAlt (
98889935 fp , compression , compressionlevel , compressionuselist , formatspecs )
9889- if (not foxfileout ):
9936+ if (not archivefileout ):
98909937 return False
98919938 fp .seek (0 , 0 )
9892- upload_file_to_internet_file (fp , outfile )
9893- return True
9939+ return upload_file_to_internet_file (fp , outfile )
98949940
98959941
98969942def upload_file_to_internet_string (ifp , url ):
@@ -9913,8 +9959,7 @@ def upload_file_to_internet_compress_string(ifp, url, compression="auto", compre
99139959 internetfileo = MkTempFile (ifp )
99149960 fp = CompressOpenFileAlt (
99159961 internetfileo , compression , compressionlevel , compressionuselist , formatspecs )
9916- if (not foxfileout ):
9962+ if (not archivefileout ):
99179963 return False
99189964 fp .seek (0 , 0 )
9919- upload_file_to_internet_file (fp , outfile )
9920- return True
9965+ return upload_file_to_internet_file (fp , outfile )
0 commit comments