-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathftp.py
More file actions
36 lines (28 loc) · 867 Bytes
/
ftp.py
File metadata and controls
36 lines (28 loc) · 867 Bytes
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
import ftplib
import Settings
class FTP:
def __init__(self):
self.f = ftplib.FTP(Settings.settings.ftp_host)
self.f.encoding = 'utf8'
self.f.connect()
self.f.login('Kepler', '063710')
self.f.set_pasv(True)
def getFileList(self):
return [[i, self.f.size(i)] for i in self.f.nlst()]
def upload(self, filePath):
try:
file = open(filePath, 'rb')
filename = filePath.split('/')[-1]
self.f.storbinary('STOR ' + filename, file)
file.close()
return True
except Exception as e:
return False
def download(self, filename, fileWriter):
try:
self.f.retrbinary('RETR ' + filename, fileWriter)
return True
except:
return False
def close(self):
self.f.quit()