I am trying to download every file from my ftp server (as a kind of backup program), and then zip it. So far all i have is this code.
import os
from ftplib import FTP
from datetime import datetime
dt = datetime.today()
start=datetime.now()
ftp = FTP("xxxxxxxxxxxxxxxxx")
ftp.login("username","password")
path = "/home/pi/backups/"+str(dt.day)+"-"+str(dt.hour)+"-backup/"
try:
os.mkdir(path)
except OSError:
print ("Creation of the directory %s failed" % path)
else:
print ("Successfully created the directory %s " % path)
files = ftp.nlst()
print(dt.minute)
directory_contents = os.listdir(path)
print(directory_contents)
for file in files:
print("Getting "+file)
ftp.retrbinary("RETR " + file,open(path + file, "wb").write)
ftp.close()
diff = dt - start
print("Backup took "+str(diff.seconds)+" seconds!")
What this code does, is it downloads every file, that isn't in a sub directory. I would like every single file and then it should download them to /home/pi/backups/"+str(dt.day)+"-"+str(dt.hour)+"-backup/
. Thank you if i get an answer i have been experimenting for 2 hours!