Commit 99092369 authored by Sergio Bruni's avatar Sergio Bruni

Last Commit

parent 8ea19ca2
......@@ -49,30 +49,30 @@ class FTP_GENERIC:
def connect(self):
if self.ftp:
if self.is_connected(): return True
time.sleep(10)
# try:
# self.ftp.quit()
# time.sleep(1)
# except Exception as e:
# self.logger.error("[%s] ftp.quit failed!!! I will try to reconnect anyway in a 10 secs. Error: [%s]" % (__name__, str(e)))
# time.sleep(10)
try:
o = urlparse(self.org)
if o.scheme == "ftp":
self.ftp = FTP(o.hostname, self.params, self.user, self.password)
elif o.scheme == "ftps":
self.ftp = ImplicitFTP_TLS(o.hostname, self.params, self.user, self.password)
else:
self.logger.error("[%s] Protocol [%s] is not managed from class [%s]" % (__name__, o.scheme, self.__class__))
return False
return True
except Exception as e:
self.logger.error("[%s] connect Error: [%s]" % (__name__, str(e)))
self.ftp = None
retry_counter = 0
while retry_counter < 3:
time.sleep((retry_counter + 1) * 10)
try:
o = urlparse(self.org)
if o.scheme == "ftp":
self.ftp = FTP(o.hostname, self.params, self.user, self.password)
elif o.scheme == "ftps":
self.ftp = ImplicitFTP_TLS(o.hostname, self.params, self.user, self.password)
else:
self.logger.error("[%s] Protocol [%s] is not managed from class [%s]" % (__name__, o.scheme, self.__class__))
return False
return True
except Exception as e:
retry_counter += 1
self.logger.error(
"[%s] connection failed! attempt number: [%d] Error: [%s]" % (__name__, retry_counter, str(e)))
self.logger.error(
"[%s] connection definitively failed! made [%d] attempts" % (__name__, retry_counter))
return False
#self.ftp.voidcmd('TYPE I')
def reconnect(self):
def reconnect(self):
try:
self.ftp.quit()
except Exception as e:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment