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": |