-
Notifications
You must be signed in to change notification settings - Fork 0
/
ftpModule.py
71 lines (50 loc) · 1.6 KB
/
ftpModule.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import sys
import socket
from ftplib import FTP
from time import sleep
from socket import _GLOBAL_DEFAULT_TIMEOUT
__all__ = ["FTP", "error_reply", "error_temp", "error_perm", "error_proto",
"all_errors"]
MSG_OOB = 0x1
FTP_PORT = 21
MAXLINE = 8192
class Error(Exception): pass
class error_reply(Error): pass
class error_temp(Error): pass
class error_perm(Error): pass
class error_proto(Error): pass
all_errors = (Error, OSError, EOFError)
CRLF = '\r\n'
B_CRLF = b'\r\n'
class ftpUploadModule(FTP):
def __init__(self, host='', user='', passwd='', acct='',
timeout=_GLOBAL_DEFAULT_TIMEOUT, source_address=None):
FTP.__init__(self, host, user, passwd, acct, timeout, source_address)
self.stop = False
self.pause = False
self.noopLoopFlag = True
def storbinary(self, cmd, fp, blocksize=8192, callback=None, rest=None):
self.voidcmd('TYPE I')
with self.transfercmd(cmd, rest) as conn:
while 1:
if self.stop or self.pause:
break
buf = fp.read(blocksize)
if not buf:
break
conn.sendall(buf)
if callback:
callback(buf)
if _SSLSocket is not None and isinstance(conn, _SSLSocket):
conn.unwrap()
return self.voidresp()
def noopLoop(self):
while self.noopLoopFlag:
self.voidcmd('NOOP')
sleep(10)
try:
import ssl
except ImportError:
_SSLSocket = None
else:
_SSLSocket = ssl.SSLSocket