@@ -4,9 +4,10 | |||
|
4 | 4 | import os |
|
5 | 5 | import glob |
|
6 | 6 | import ftplib |
|
7 | import multiprocessing | |
|
7 | 8 | from model.proc.jroproc_base import ProcessingUnit, Operation |
|
8 | 9 | |
|
9 | class FTP(): | |
|
10 | class FTP(object): | |
|
10 | 11 | """ |
|
11 | 12 | Ftp is a public class used to define custom File Transfer Protocol from "ftplib" python module |
|
12 | 13 | |
@@ -305,31 +306,31 class SendByFTP(Operation): | |||
|
305 | 306 | print ValueError, 'Error FTP' |
|
306 | 307 | print "don't worry the program is running..." |
|
307 | 308 | |
|
308 |
def |
|
|
309 | if not(self.status): | |
|
310 | return | |
|
311 | try: | |
|
312 | self.ftpObj = FTP(server, username, password, remotefolder) | |
|
313 | except: | |
|
314 | self.error_print(ValueError) | |
|
315 | self.status = 0 | |
|
309 | def worker_ftp(self, server, username, password, remotefolder, filenameList): | |
|
310 | ||
|
311 | self.ftpObj = FTP(server, username, password, remotefolder) | |
|
312 | for filename in filenameList: | |
|
313 | self.ftpObj.upload(filename) | |
|
314 | self.ftpObj.close() | |
|
316 | 315 | |
|
317 | def put(self): | |
|
316 | def ftp_thread(self, server, username, password, remotefolder): | |
|
318 | 317 | if not(self.status): |
|
319 | 318 | return |
|
320 | 319 | |
|
321 | try: | |
|
322 | for filename in self.filenameList: | |
|
323 | self.ftpObj.upload(filename) | |
|
324 | except: | |
|
325 | self.error_print(ValueError) | |
|
320 | p = multiprocessing.Process(target=self.worker_ftp, args=(server, username, password, remotefolder, self.filenameList,)) | |
|
321 | p.start() | |
|
322 | ||
|
323 | p.join(3) | |
|
324 | ||
|
325 | if p.is_alive(): | |
|
326 | p.terminate() | |
|
327 | p.join() | |
|
328 | print 'killing ftp process...' | |
|
326 | 329 | self.status = 0 |
|
327 | ||
|
328 | def close(self): | |
|
329 | if not(self.status): | |
|
330 | 330 | return |
|
331 | 331 | |
|
332 |
self. |
|
|
332 | self.status = 1 | |
|
333 | return | |
|
333 | 334 | |
|
334 | 335 | def filterByExt(self, ext, localfolder): |
|
335 | 336 | fnameList = glob.glob1(localfolder,ext) |
@@ -344,11 +345,9 class SendByFTP(Operation): | |||
|
344 | 345 | if self.counter >= period: |
|
345 | 346 | self.filterByExt(ext, localfolder) |
|
346 | 347 | |
|
347 |
self. |
|
|
348 | ||
|
349 | self.put() | |
|
350 | ||
|
351 | self.close() | |
|
352 | ||
|
348 | self.ftp_thread(server, username, password, remotefolder) | |
|
349 | ||
|
353 | 350 | self.counter = 0 |
|
354 | 351 | |
|
352 | self.status = 1 | |
|
353 |
General Comments 0
You need to be logged in to leave comments.
Login now