I've been trying to write a python code which can archive the files of ftp server into one zip file and download it :
And so far I understand I need to use ftplib for this:
import os
from time import strftime
from ftplib import FTP
day = strftime("%d")
today = strftime("%d-%m-%Y")
link = FTP(ftphost)
link.login(passwd = ftp_pass, user = ftp_user)
link.cwd(file_path)
And I think I need to use FTP.sendcmd
function to send a command to FTP server to have it archive all the files into one and actually I am not really sure which command I need to send though.
To download the file, the function seems legit to me:
import os
def download(ftp,file, localdir):
f = open(os.path.join(localdir, file),"wb")
ftp.retrbinary("RETR " + file,f.write)
f.close()
Can someone put together what I've been trying to do here please?