eric6/E5Network/E5Ftp.py

changeset 7628
f904d0eef264
parent 7360
9190402e4505
child 7780
41420f82c0ac
equal deleted inserted replaced
7626:7f643d41464e 7628:f904d0eef264
7 Module implementing an extension to the Python FTP class to support FTP 7 Module implementing an extension to the Python FTP class to support FTP
8 proxies. 8 proxies.
9 """ 9 """
10 10
11 11
12 import ftplib 12 import ftplib # secok
13 from socket import _GLOBAL_DEFAULT_TIMEOUT 13 from socket import _GLOBAL_DEFAULT_TIMEOUT
14 14
15 15
16 class E5FtpProxyError(ftplib.Error): 16 class E5FtpProxyError(ftplib.Error):
17 """ 17 """
59 class E5Ftp(ftplib.FTP): 59 class E5Ftp(ftplib.FTP):
60 """ 60 """
61 Class implementing an extension to the Python FTP class to support FTP 61 Class implementing an extension to the Python FTP class to support FTP
62 proxies. 62 proxies.
63 """ 63 """
64 def __init__(self, host="", user="", password="", acct="", 64 def __init__(self, host="", user="", password="", acct="", # secok
65 proxyType=E5FtpProxyType.NoProxy, proxyHost="", 65 proxyType=E5FtpProxyType.NoProxy, proxyHost="",
66 proxyPort=ftplib.FTP_PORT, proxyUser="", proxyPassword="", 66 proxyPort=ftplib.FTP_PORT, proxyUser="", proxyPassword="",
67 proxyAccount="", timeout=_GLOBAL_DEFAULT_TIMEOUT): 67 proxyAccount="", timeout=_GLOBAL_DEFAULT_TIMEOUT):
68 """ 68 """
69 Constructor 69 Constructor
165 self.__proxyHost, self.__proxyPort, self.__timeout) 165 self.__proxyHost, self.__proxyPort, self.__timeout)
166 else: 166 else:
167 return super(E5Ftp, self).connect( 167 return super(E5Ftp, self).connect(
168 self.__host, self.__port, self.__timeout) 168 self.__host, self.__port, self.__timeout)
169 169
170 def login(self, user="", password="", acct=""): 170 def login(self, user="", password="", acct=""): # secok
171 """ 171 """
172 Public method to login to the FTP server. 172 Public method to login to the FTP server.
173 173
174 This extended method respects the FTP proxy configuration. There are 174 This extended method respects the FTP proxy configuration. There are
175 many different FTP proxy products available. But unfortunately there 175 many different FTP proxy products available. But unfortunately there
255 """ 255 """
256 if not user: 256 if not user:
257 user = "anonymous" 257 user = "anonymous"
258 if not password: 258 if not password:
259 # make sure it is a string 259 # make sure it is a string
260 password = "" 260 password = "" # secok
261 if not acct: 261 if not acct:
262 # make sure it is a string 262 # make sure it is a string
263 acct = "" 263 acct = ""
264 if user == "anonymous" and password in {'', '-'}: 264 if user == "anonymous" and password in {'', '-'}:
265 password += "anonymous@" 265 password += "anonymous@"
324 if resp[0] == "3": 324 if resp[0] == "3":
325 resp = self.sendcmd("PASS " + password) 325 resp = self.sendcmd("PASS " + password)
326 if resp[0] == "3": 326 if resp[0] == "3":
327 resp = self.sendcmd("ACCT " + acct) 327 resp = self.sendcmd("ACCT " + acct)
328 if resp[0] != "2": 328 if resp[0] != "2":
329 raise ftplib.error_reply(resp) 329 raise ftplib.error_reply(resp) # secok
330 330
331 if self.__proxyType == E5FtpProxyType.AuthResp: 331 if self.__proxyType == E5FtpProxyType.AuthResp:
332 # authorize to the FTP proxy 332 # authorize to the FTP proxy
333 presp = self.sendcmd("AUTH " + self.__proxyUser) 333 presp = self.sendcmd("AUTH " + self.__proxyUser)
334 if presp[0] == "3": 334 if presp[0] == "3":

eric ide

mercurial