@@ -195,6 +195,7 class SendToFTP(Operation): | |||||
195 | Operation.__init__(self) |
|
195 | Operation.__init__(self) | |
196 | self.ftp = None |
|
196 | self.ftp = None | |
197 | self.ready = False |
|
197 | self.ready = False | |
|
198 | self.current_time = time.time() | |||
198 |
|
199 | |||
199 | def setup(self, server, username, password, timeout, **kwargs): |
|
200 | def setup(self, server, username, password, timeout, **kwargs): | |
200 | ''' |
|
201 | ''' | |
@@ -219,7 +220,7 class SendToFTP(Operation): | |||||
219 |
|
220 | |||
220 | log.log('Connecting to ftp://{}'.format(self.server), self.name) |
|
221 | log.log('Connecting to ftp://{}'.format(self.server), self.name) | |
221 | try: |
|
222 | try: | |
222 |
self.ftp = ftplib.FTP(self.server, timeout= |
|
223 | self.ftp = ftplib.FTP(self.server, timeout=1) | |
223 | except ftplib.all_errors: |
|
224 | except ftplib.all_errors: | |
224 | log.error('Server connection fail: {}'.format(self.server), self.name) |
|
225 | log.error('Server connection fail: {}'.format(self.server), self.name) | |
225 | if self.ftp is not None: |
|
226 | if self.ftp is not None: | |
@@ -245,6 +246,11 class SendToFTP(Operation): | |||||
245 | def check(self): |
|
246 | def check(self): | |
246 |
|
247 | |||
247 | try: |
|
248 | try: | |
|
249 | if not self.ready: | |||
|
250 | if time.time()-self.current_time < self.timeout: | |||
|
251 | return | |||
|
252 | else: | |||
|
253 | self.current_time = time.time() | |||
248 | self.ftp.voidcmd("NOOP") |
|
254 | self.ftp.voidcmd("NOOP") | |
249 | except: |
|
255 | except: | |
250 | log.warning('Connection lost... trying to reconnect', self.name) |
|
256 | log.warning('Connection lost... trying to reconnect', self.name) | |
@@ -328,7 +334,7 class SendToFTP(Operation): | |||||
328 | self.times[x] = self.dataOut.utctime |
|
334 | self.times[x] = self.dataOut.utctime | |
329 | self.latest[x] = srcname |
|
335 | self.latest[x] = srcname | |
330 |
|
336 | |||
331 |
def run(self, dataOut, server, username, password, timeout= |
|
337 | def run(self, dataOut, server, username, password, timeout=60, **kwargs): | |
332 |
|
338 | |||
333 | if not self.isConfig: |
|
339 | if not self.isConfig: | |
334 | self.setup( |
|
340 | self.setup( | |
@@ -343,7 +349,8 class SendToFTP(Operation): | |||||
343 |
|
349 | |||
344 | self.dataOut = dataOut |
|
350 | self.dataOut = dataOut | |
345 | self.check() |
|
351 | self.check() | |
346 |
self. |
|
352 | if self.ready: | |
|
353 | self.send_files() | |||
347 |
|
354 | |||
348 | def close(self): |
|
355 | def close(self): | |
349 |
|
356 |
General Comments 0
You need to be logged in to leave comments.
Login now