forked from arnekaas/DSMR-P1-usb-logger
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathupload_data_to_demo_server.py
executable file
·54 lines (42 loc) · 1.34 KB
/
upload_data_to_demo_server.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
#function: Upload to server
import ftplib
def upload_to_server(path_to_file):
session = ftplib.FTP('ftp.allianders.nl','[email protected]','uploadyourdata')
file = open(path_to_file,'rb') # file to send
try:
print ("Upload started...")
session.storbinary('STOR '+path_to_file, file) # send the file
print ("Upload succeded")
except:
print ("Upload failed...")
file.close() # close file and FTP
session.quit()
#save all files in de folder data to server
path= "./upload/"
from os import listdir
from os.path import isfile, join, realpath
onlyfiles = [f for f in listdir(path) if isfile(join(path, f))]
print (onlyfiles)
for file in onlyfiles:
path_to_file = path + file
upload_to_server(path_to_file)
#test download
import ftplib
ftp = ftplib.FTP()
host = "ftp.allianders.nl"
path = join(realpath(__file__),"logs")
filename = 'example.db'
port = 21
ftp.connect(host, port)
print (ftp.getwelcome())
try:
print ("Logging in...")
ftp.login('[email protected]','uploadyourdata')
ftp.cwd(path)
try:
ftp.retrbinary("RETR " + filename ,open(filename, 'wb').write)
print ("Downloaded: " +filename)
except:
print("Error during download")
except:
print ("Failed to login")