@@ -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" :
@@ -9378,8 +9378,8 @@ def detect_cwd(ftp, file_dir):
93789378
93799379def download_file_from_ftp_file (url ):
93809380 urlparts = urlparse (url )
9381- file_name = os .path .basename (urlparts .path )
9382- file_dir = os .path .dirname (urlparts .path )
9381+ file_name = os .path .basename (unquote ( urlparts .path ) )
9382+ file_dir = os .path .dirname (unquote ( urlparts .path ) )
93839383 if (urlparts .username is not None ):
93849384 ftp_username = urlparts .username
93859385 else :
@@ -9419,7 +9419,7 @@ def download_file_from_ftp_file(url):
94199419 ftp .auth ()
94209420 except all_errors :
94219421 pass
9422- ftp .login (urlparts . username , urlparts . password )
9422+ ftp .login (ftp_username , ftp_password )
94239423 if (urlparts .scheme == "ftps" or isinstance (ftp , FTP_TLS )):
94249424 try :
94259425 ftp .prot_p ()
@@ -9440,20 +9440,20 @@ def download_file_from_ftp_file(url):
94409440 if (is_cwd_allowed ):
94419441 ftp .retrbinary ("RETR " + file_name , ftpfile .write )
94429442 else :
9443- ftp .retrbinary ("RETR " + urlparts .path , ftpfile .write )
9443+ ftp .retrbinary ("RETR " + unquote ( urlparts .path ) , ftpfile .write )
94449444 except all_errors :
94459445 try :
94469446 ftp .set_pasv (True )
94479447 if (is_cwd_allowed ):
94489448 ftp .retrbinary ("RETR " + file_name , ftpfile .write )
94499449 else :
9450- ftp .retrbinary ("RETR " + urlparts .path , ftpfile .write )
9450+ ftp .retrbinary ("RETR " + unquote ( urlparts .path ) , ftpfile .write )
94519451 except all_errors :
94529452 ftp .set_pasv (False )
94539453 if (is_cwd_allowed ):
94549454 ftp .retrbinary ("RETR " + file_name , ftpfile .write )
94559455 else :
9456- ftp .retrbinary ("RETR " + urlparts .path , ftpfile .write )
9456+ ftp .retrbinary ("RETR " + unquote ( urlparts .path ) , ftpfile .write )
94579457 ftp .close ()
94589458 ftpfile .seek (0 , 0 )
94599459 return ftpfile
@@ -9476,8 +9476,8 @@ def download_file_from_ftps_string(url):
94769476
94779477def upload_file_to_ftp_file (ftpfile , url ):
94789478 urlparts = urlparse (url )
9479- file_name = os .path .basename (urlparts .path )
9480- file_dir = os .path .dirname (urlparts .path )
9479+ file_name = os .path .basename (unquote ( urlparts .path ) )
9480+ file_dir = os .path .dirname (unquote ( urlparts .path ) )
94819481 if (urlparts .username is not None ):
94829482 ftp_username = urlparts .username
94839483 else :
@@ -9517,7 +9517,7 @@ def upload_file_to_ftp_file(ftpfile, url):
95179517 ftp .auth ()
95189518 except all_errors :
95199519 pass
9520- ftp .login (urlparts . username , urlparts . password )
9520+ ftp .login (ftp_username , ftp_password )
95219521 if (urlparts .scheme == "ftps" or isinstance (ftp , FTP_TLS )):
95229522 try :
95239523 ftp .prot_p ()
@@ -9538,20 +9538,20 @@ def upload_file_to_ftp_file(ftpfile, url):
95389538 if (is_cwd_allowed ):
95399539 ftp .storbinary ("STOR " + file_name , ftpfile )
95409540 else :
9541- ftp .storbinary ("STOR " + urlparts .path , ftpfile )
9541+ ftp .storbinary ("STOR " + unquote ( urlparts .path ) , ftpfile )
95429542 except all_errors :
95439543 try :
95449544 ftp .set_pasv (True )
95459545 if (is_cwd_allowed ):
95469546 ftp .storbinary ("STOR " + file_name , ftpfile )
95479547 else :
9548- ftp .storbinary ("STOR " + urlparts .path , ftpfile )
9548+ ftp .storbinary ("STOR " + unquote ( urlparts .path ) , ftpfile )
95499549 except all_errors :
95509550 ftp .set_pasv (False )
95519551 if (is_cwd_allowed ):
95529552 ftp .storbinary ("STOR " + file_name , ftpfile )
95539553 else :
9554- ftp .storbinary ("STOR " + urlparts .path , ftpfile )
9554+ ftp .storbinary ("STOR " + unquote ( urlparts .path ) , ftpfile )
95559555 ftp .close ()
95569556 ftpfile .seek (0 , 0 )
95579557 return ftpfile
@@ -9690,8 +9690,8 @@ def download_file_from_http_string(url, headers=geturls_headers_pyfile_python_al
96909690if (haveparamiko ):
96919691 def download_file_from_sftp_file (url ):
96929692 urlparts = urlparse (url )
9693- file_name = os .path .basename (urlparts .path )
9694- file_dir = os .path .dirname (urlparts .path )
9693+ file_name = os .path .basename (unquote ( urlparts .path ) )
9694+ file_dir = os .path .dirname (unquote ( urlparts .path ) )
96959695 sftp_port = urlparts .port
96969696 if (urlparts .port is None ):
96979697 sftp_port = 22
@@ -9718,7 +9718,7 @@ def download_file_from_sftp_file(url):
97189718 ssh .set_missing_host_key_policy (paramiko .AutoAddPolicy ())
97199719 try :
97209720 ssh .connect (urlparts .hostname , port = sftp_port ,
9721- username = urlparts . username , password = urlparts .password )
9721+ username = sftp_username , password = urlparts .password )
97229722 except paramiko .ssh_exception .SSHException :
97239723 return False
97249724 except socket .gaierror :
@@ -9729,7 +9729,7 @@ def download_file_from_sftp_file(url):
97299729 return False
97309730 sftp = ssh .open_sftp ()
97319731 sftpfile = MkTempFile ()
9732- sftp .getfo (urlparts .path , sftpfile )
9732+ sftp .getfo (unquote ( urlparts .path ) , sftpfile )
97339733 sftp .close ()
97349734 ssh .close ()
97359735 sftpfile .seek (0 , 0 )
@@ -9751,8 +9751,8 @@ def download_file_from_sftp_string(url):
97519751if (haveparamiko ):
97529752 def upload_file_to_sftp_file (sftpfile , url ):
97539753 urlparts = urlparse (url )
9754- file_name = os .path .basename (urlparts .path )
9755- file_dir = os .path .dirname (urlparts .path )
9754+ file_name = os .path .basename (unquote ( urlparts .path ) )
9755+ file_dir = os .path .dirname (unquote ( urlparts .path ) )
97569756 sftp_port = urlparts .port
97579757 if (urlparts .port is None ):
97589758 sftp_port = 22
@@ -9769,7 +9769,7 @@ def upload_file_to_sftp_file(sftpfile, url):
97699769 else :
97709770 sftp_password = ""
97719771 if (urlparts .scheme == "ftp" ):
9772- return upload_file_to_ftp_file (url )
9772+ return upload_file_to_ftp_file (sftpfile , url )
97739773 elif (urlparts .scheme == "http" or urlparts .scheme == "https" ):
97749774 return False
97759775 if (urlparts .scheme != "sftp" ):
@@ -9779,7 +9779,7 @@ def upload_file_to_sftp_file(sftpfile, url):
97799779 ssh .set_missing_host_key_policy (paramiko .AutoAddPolicy ())
97809780 try :
97819781 ssh .connect (urlparts .hostname , port = sftp_port ,
9782- username = urlparts . username , password = urlparts . password )
9782+ username = sftp_username , password = sftp_password )
97839783 except paramiko .ssh_exception .SSHException :
97849784 return False
97859785 except socket .gaierror :
@@ -9789,7 +9789,8 @@ def upload_file_to_sftp_file(sftpfile, url):
97899789 log .info ("Error With URL " + url )
97909790 return False
97919791 sftp = ssh .open_sftp ()
9792- sftp .putfo (sftpfile , urlparts .path )
9792+ sftpfile .seek (0 , 0 )
9793+ sftp .putfo (sftpfile , unquote (urlparts .path ))
97939794 sftp .close ()
97949795 ssh .close ()
97959796 sftpfile .seek (0 , 0 )
@@ -9811,8 +9812,8 @@ def upload_file_to_sftp_string(url):
98119812if (havepysftp ):
98129813 def download_file_from_pysftp_file (url ):
98139814 urlparts = urlparse (url )
9814- file_name = os .path .basename (urlparts .path )
9815- file_dir = os .path .dirname (urlparts .path )
9815+ file_name = os .path .basename (unquote ( urlparts .path ) )
9816+ file_dir = os .path .dirname (unquote ( urlparts .path ) )
98169817 sftp_port = urlparts .port
98179818 if (urlparts .port is None ):
98189819 sftp_port = 22
@@ -9835,8 +9836,8 @@ def download_file_from_pysftp_file(url):
98359836 if (urlparts .scheme != "sftp" ):
98369837 return False
98379838 try :
9838- pysftp .Connection (urlparts .hostname , port = sftp_port ,
9839- username = urlparts . username , password = urlparts . password )
9839+ sftp = pysftp .Connection (urlparts .hostname , port = sftp_port ,
9840+ username = sftp_username , password = sftp_password )
98409841 except paramiko .ssh_exception .SSHException :
98419842 return False
98429843 except socket .gaierror :
@@ -9845,9 +9846,8 @@ def download_file_from_pysftp_file(url):
98459846 except socket .timeout :
98469847 log .info ("Error With URL " + url )
98479848 return False
9848- sftp = ssh .open_sftp ()
98499849 sftpfile = MkTempFile ()
9850- sftp .getfo (urlparts .path , sftpfile )
9850+ sftp .getfo (unquote ( urlparts .path ) , sftpfile )
98519851 sftp .close ()
98529852 ssh .close ()
98539853 sftpfile .seek (0 , 0 )
@@ -9869,8 +9869,8 @@ def download_file_from_pysftp_string(url):
98699869if (havepysftp ):
98709870 def upload_file_to_pysftp_file (sftpfile , url ):
98719871 urlparts = urlparse (url )
9872- file_name = os .path .basename (urlparts .path )
9873- file_dir = os .path .dirname (urlparts .path )
9872+ file_name = os .path .basename (unquote ( urlparts .path ) )
9873+ file_dir = os .path .dirname (unquote ( urlparts .path ) )
98749874 sftp_port = urlparts .port
98759875 if (urlparts .port is None ):
98769876 sftp_port = 22
@@ -9887,14 +9887,14 @@ def upload_file_to_pysftp_file(sftpfile, url):
98879887 else :
98889888 sftp_password = ""
98899889 if (urlparts .scheme == "ftp" ):
9890- return upload_file_to_ftp_file (url )
9890+ return upload_file_to_ftp_file (sftpfile , url )
98919891 elif (urlparts .scheme == "http" or urlparts .scheme == "https" ):
98929892 return False
98939893 if (urlparts .scheme != "sftp" ):
98949894 return False
98959895 try :
9896- pysftp .Connection (urlparts .hostname , port = sftp_port ,
9897- username = urlparts . username , password = urlparts . password )
9896+ sftp = pysftp .Connection (urlparts .hostname , port = sftp_port ,
9897+ username = sftp_username , password = sftp_password )
98989898 except paramiko .ssh_exception .SSHException :
98999899 return False
99009900 except socket .gaierror :
@@ -9903,8 +9903,8 @@ def upload_file_to_pysftp_file(sftpfile, url):
99039903 except socket .timeout :
99049904 log .info ("Error With URL " + url )
99059905 return False
9906- sftp = ssh . open_sftp ( )
9907- sftp .putfo (sftpfile , urlparts .path )
9906+ sftpfile . seek ( 0 , 0 )
9907+ sftp .putfo (sftpfile , unquote ( urlparts .path ) )
99089908 sftp .close ()
99099909 ssh .close ()
99109910 sftpfile .seek (0 , 0 )
0 commit comments