Reputation: 115
I have the following code:
ftp = ftplib.FTP(ftp_srv)
ftp.login(ftp_usr, ftp_pass)
for item in list:
f = open(item.localName,"wb")
ftp.retrbinary("RETR " + item.remoteName, f.write)
ftp.quit()
In perl this was very easy:
$ftp->get($ftp_file, $local_file)
EDIT: The code above does not work. I would like to download the remoteName file to the local machine and on the local machine that file to be named localName. How do I do that? :D EDIT2: made it a list
Thank you
Upvotes: 0
Views: 8060
Reputation: 485
The main problems with your code are that:
item
is never actually used in the for
looplocalName
or remoteName
are not specified anywhereThis code works on my machine:
import ftplib
ftp_srv = 'ftp.example.com'
ftp_usr = 'user'
ftp_pass = 'password'
ftp = ftplib.FTP(ftp_srv)
ftp.login(ftp_usr, ftp_pass)
files = [('remote_file1', 'local_file1'), ('remote_file2', 'local_file2')]
for file_ in files:
with open(file_[1], "wb") as f:
ftp.retrbinary("RETR " + file_[0], f.write)
ftp.quit()
Each file_
is a tuple which contains the name of the file on the server, and the name you want it to have on your local machine, which are referred to using the square bracket notation.
Upvotes: 2