Reputation: 81721
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?
Upvotes: 1
Views: 2426
Reputation: 81721
OK, so I've found the solution I believe.
I need to use SSH (Secure Shell) or sFTP I think they mean same thing. There is a lib called Paramiko and it offers sending commands, connection, etc. for SSH. It seems using ftplib won't help since you cannot run Shell Commands via ftplib. You need a secure connection to do that.
Upvotes: 1