@@ -102,9 +102,9 @@ def to_text(s, encoding="utf-8", errors="ignore"):
102102
103103# URL Parsing
104104try :
105- from urllib .parse import urlparse , urlunparse
105+ from urllib .parse import urlparse , urlunparse , unquote
106106except ImportError :
107- from urlparse import urlparse , urlunparse
107+ from urlparse import urlparse , urlunparse , unquote
108108
109109# Windows-specific setup
110110if os .name == "nt" :
@@ -9367,8 +9367,8 @@ def detect_cwd(ftp, file_dir):
93679367
93689368def download_file_from_ftp_file (url ):
93699369 urlparts = urlparse (url )
9370- file_name = os .path .basename (urlparts .path )
9371- file_dir = os .path .dirname (urlparts .path )
9370+ file_name = os .path .basename (unquote ( urlparts .path ) )
9371+ file_dir = os .path .dirname (unquote ( urlparts .path ) )
93729372 if (urlparts .username is not None ):
93739373 ftp_username = urlparts .username
93749374 else :
@@ -9408,7 +9408,7 @@ def download_file_from_ftp_file(url):
94089408 ftp .auth ()
94099409 except all_errors :
94109410 pass
9411- ftp .login (urlparts . username , urlparts . password )
9411+ ftp .login (ftp_username , ftp_password )
94129412 if (urlparts .scheme == "ftps" or isinstance (ftp , FTP_TLS )):
94139413 try :
94149414 ftp .prot_p ()
@@ -9429,20 +9429,20 @@ def download_file_from_ftp_file(url):
94299429 if (is_cwd_allowed ):
94309430 ftp .retrbinary ("RETR " + file_name , ftpfile .write )
94319431 else :
9432- ftp .retrbinary ("RETR " + urlparts .path , ftpfile .write )
9432+ ftp .retrbinary ("RETR " + unquote ( urlparts .path ) , ftpfile .write )
94339433 except all_errors :
94349434 try :
94359435 ftp .set_pasv (True )
94369436 if (is_cwd_allowed ):
94379437 ftp .retrbinary ("RETR " + file_name , ftpfile .write )
94389438 else :
9439- ftp .retrbinary ("RETR " + urlparts .path , ftpfile .write )
9439+ ftp .retrbinary ("RETR " + unquote ( urlparts .path ) , ftpfile .write )
94409440 except all_errors :
94419441 ftp .set_pasv (False )
94429442 if (is_cwd_allowed ):
94439443 ftp .retrbinary ("RETR " + file_name , ftpfile .write )
94449444 else :
9445- ftp .retrbinary ("RETR " + urlparts .path , ftpfile .write )
9445+ ftp .retrbinary ("RETR " + unquote ( urlparts .path ) , ftpfile .write )
94469446 ftp .close ()
94479447 ftpfile .seek (0 , 0 )
94489448 return ftpfile
@@ -9465,8 +9465,8 @@ def download_file_from_ftps_string(url):
94659465
94669466def upload_file_to_ftp_file (ftpfile , url ):
94679467 urlparts = urlparse (url )
9468- file_name = os .path .basename (urlparts .path )
9469- file_dir = os .path .dirname (urlparts .path )
9468+ file_name = os .path .basename (unquote ( urlparts .path ) )
9469+ file_dir = os .path .dirname (unquote ( urlparts .path ) )
94709470 if (urlparts .username is not None ):
94719471 ftp_username = urlparts .username
94729472 else :
@@ -9506,7 +9506,7 @@ def upload_file_to_ftp_file(ftpfile, url):
95069506 ftp .auth ()
95079507 except all_errors :
95089508 pass
9509- ftp .login (urlparts . username , urlparts . password )
9509+ ftp .login (ftp_username , ftp_password )
95109510 if (urlparts .scheme == "ftps" or isinstance (ftp , FTP_TLS )):
95119511 try :
95129512 ftp .prot_p ()
@@ -9527,20 +9527,20 @@ def upload_file_to_ftp_file(ftpfile, url):
95279527 if (is_cwd_allowed ):
95289528 ftp .storbinary ("STOR " + file_name , ftpfile )
95299529 else :
9530- ftp .storbinary ("STOR " + urlparts .path , ftpfile )
9530+ ftp .storbinary ("STOR " + unquote ( urlparts .path ) , ftpfile )
95319531 except all_errors :
95329532 try :
95339533 ftp .set_pasv (True )
95349534 if (is_cwd_allowed ):
95359535 ftp .storbinary ("STOR " + file_name , ftpfile )
95369536 else :
9537- ftp .storbinary ("STOR " + urlparts .path , ftpfile )
9537+ ftp .storbinary ("STOR " + unquote ( urlparts .path ) , ftpfile )
95389538 except all_errors :
95399539 ftp .set_pasv (False )
95409540 if (is_cwd_allowed ):
95419541 ftp .storbinary ("STOR " + file_name , ftpfile )
95429542 else :
9543- ftp .storbinary ("STOR " + urlparts .path , ftpfile )
9543+ ftp .storbinary ("STOR " + unquote ( urlparts .path ) , ftpfile )
95449544 ftp .close ()
95459545 ftpfile .seek (0 , 0 )
95469546 return ftpfile
@@ -9679,8 +9679,8 @@ def download_file_from_http_string(url, headers=geturls_headers_pyfile_python_al
96799679if (haveparamiko ):
96809680 def download_file_from_sftp_file (url ):
96819681 urlparts = urlparse (url )
9682- file_name = os .path .basename (urlparts .path )
9683- file_dir = os .path .dirname (urlparts .path )
9682+ file_name = os .path .basename (unquote ( urlparts .path ) )
9683+ file_dir = os .path .dirname (unquote ( urlparts .path ) )
96849684 sftp_port = urlparts .port
96859685 if (urlparts .port is None ):
96869686 sftp_port = 22
@@ -9707,7 +9707,7 @@ def download_file_from_sftp_file(url):
97079707 ssh .set_missing_host_key_policy (paramiko .AutoAddPolicy ())
97089708 try :
97099709 ssh .connect (urlparts .hostname , port = sftp_port ,
9710- username = urlparts . username , password = urlparts .password )
9710+ username = sftp_username , password = urlparts .password )
97119711 except paramiko .ssh_exception .SSHException :
97129712 return False
97139713 except socket .gaierror :
@@ -9718,7 +9718,7 @@ def download_file_from_sftp_file(url):
97189718 return False
97199719 sftp = ssh .open_sftp ()
97209720 sftpfile = MkTempFile ()
9721- sftp .getfo (urlparts .path , sftpfile )
9721+ sftp .getfo (unquote ( urlparts .path ) , sftpfile )
97229722 sftp .close ()
97239723 ssh .close ()
97249724 sftpfile .seek (0 , 0 )
@@ -9740,8 +9740,8 @@ def download_file_from_sftp_string(url):
97409740if (haveparamiko ):
97419741 def upload_file_to_sftp_file (sftpfile , url ):
97429742 urlparts = urlparse (url )
9743- file_name = os .path .basename (urlparts .path )
9744- file_dir = os .path .dirname (urlparts .path )
9743+ file_name = os .path .basename (unquote ( urlparts .path ) )
9744+ file_dir = os .path .dirname (unquote ( urlparts .path ) )
97459745 sftp_port = urlparts .port
97469746 if (urlparts .port is None ):
97479747 sftp_port = 22
@@ -9758,7 +9758,7 @@ def upload_file_to_sftp_file(sftpfile, url):
97589758 else :
97599759 sftp_password = ""
97609760 if (urlparts .scheme == "ftp" ):
9761- return upload_file_to_ftp_file (url )
9761+ return upload_file_to_ftp_file (sftpfile , url )
97629762 elif (urlparts .scheme == "http" or urlparts .scheme == "https" ):
97639763 return False
97649764 if (urlparts .scheme != "sftp" ):
@@ -9768,7 +9768,7 @@ def upload_file_to_sftp_file(sftpfile, url):
97689768 ssh .set_missing_host_key_policy (paramiko .AutoAddPolicy ())
97699769 try :
97709770 ssh .connect (urlparts .hostname , port = sftp_port ,
9771- username = urlparts . username , password = urlparts . password )
9771+ username = sftp_username , password = sftp_password )
97729772 except paramiko .ssh_exception .SSHException :
97739773 return False
97749774 except socket .gaierror :
@@ -9778,7 +9778,8 @@ def upload_file_to_sftp_file(sftpfile, url):
97789778 log .info ("Error With URL " + url )
97799779 return False
97809780 sftp = ssh .open_sftp ()
9781- sftp .putfo (sftpfile , urlparts .path )
9781+ sftpfile .seek (0 , 0 )
9782+ sftp .putfo (sftpfile , unquote (urlparts .path ))
97829783 sftp .close ()
97839784 ssh .close ()
97849785 sftpfile .seek (0 , 0 )
@@ -9800,8 +9801,8 @@ def upload_file_to_sftp_string(url):
98009801if (havepysftp ):
98019802 def download_file_from_pysftp_file (url ):
98029803 urlparts = urlparse (url )
9803- file_name = os .path .basename (urlparts .path )
9804- file_dir = os .path .dirname (urlparts .path )
9804+ file_name = os .path .basename (unquote ( urlparts .path ) )
9805+ file_dir = os .path .dirname (unquote ( urlparts .path ) )
98059806 sftp_port = urlparts .port
98069807 if (urlparts .port is None ):
98079808 sftp_port = 22
@@ -9824,8 +9825,8 @@ def download_file_from_pysftp_file(url):
98249825 if (urlparts .scheme != "sftp" ):
98259826 return False
98269827 try :
9827- pysftp .Connection (urlparts .hostname , port = sftp_port ,
9828- username = urlparts . username , password = urlparts . password )
9828+ sftp = pysftp .Connection (urlparts .hostname , port = sftp_port ,
9829+ username = sftp_username , password = sftp_password )
98299830 except paramiko .ssh_exception .SSHException :
98309831 return False
98319832 except socket .gaierror :
@@ -9834,9 +9835,8 @@ def download_file_from_pysftp_file(url):
98349835 except socket .timeout :
98359836 log .info ("Error With URL " + url )
98369837 return False
9837- sftp = ssh .open_sftp ()
98389838 sftpfile = MkTempFile ()
9839- sftp .getfo (urlparts .path , sftpfile )
9839+ sftp .getfo (unquote ( urlparts .path ) , sftpfile )
98409840 sftp .close ()
98419841 ssh .close ()
98429842 sftpfile .seek (0 , 0 )
@@ -9858,8 +9858,8 @@ def download_file_from_pysftp_string(url):
98589858if (havepysftp ):
98599859 def upload_file_to_pysftp_file (sftpfile , url ):
98609860 urlparts = urlparse (url )
9861- file_name = os .path .basename (urlparts .path )
9862- file_dir = os .path .dirname (urlparts .path )
9861+ file_name = os .path .basename (unquote ( urlparts .path ) )
9862+ file_dir = os .path .dirname (unquote ( urlparts .path ) )
98639863 sftp_port = urlparts .port
98649864 if (urlparts .port is None ):
98659865 sftp_port = 22
@@ -9876,14 +9876,14 @@ def upload_file_to_pysftp_file(sftpfile, url):
98769876 else :
98779877 sftp_password = ""
98789878 if (urlparts .scheme == "ftp" ):
9879- return upload_file_to_ftp_file (url )
9879+ return upload_file_to_ftp_file (sftpfile , url )
98809880 elif (urlparts .scheme == "http" or urlparts .scheme == "https" ):
98819881 return False
98829882 if (urlparts .scheme != "sftp" ):
98839883 return False
98849884 try :
9885- pysftp .Connection (urlparts .hostname , port = sftp_port ,
9886- username = urlparts . username , password = urlparts . password )
9885+ sftp = pysftp .Connection (urlparts .hostname , port = sftp_port ,
9886+ username = sftp_username , password = sftp_password )
98879887 except paramiko .ssh_exception .SSHException :
98889888 return False
98899889 except socket .gaierror :
@@ -9892,8 +9892,8 @@ def upload_file_to_pysftp_file(sftpfile, url):
98929892 except socket .timeout :
98939893 log .info ("Error With URL " + url )
98949894 return False
9895- sftp = ssh . open_sftp ( )
9896- sftp .putfo (sftpfile , urlparts .path )
9895+ sftpfile . seek ( 0 , 0 )
9896+ sftp .putfo (sftpfile , unquote ( urlparts .path ) )
98979897 sftp .close ()
98989898 ssh .close ()
98999899 sftpfile .seek (0 , 0 )
0 commit comments