Reputation: 117
I'm using the ftplib to connect to my FTP-server.
I want to download a file from my FTP-server to a specified directory on my computer. I have this simple code:
def download(ftp,file):
f = open(file,"wb")
ftp.retrbinary("RETR " + file,f.write)
f.close()
What do I have to add to this code to download the file to my requested directory?
Thanks!
Upvotes: 0
Views: 375
Reputation: 5069
Update the call to open
with the local path you want to write to. For example:
import os
def download(ftp,file, localdir):
f = open(os.path.join(localdir, file),"wb")
ftp.retrbinary("RETR " + file,f.write)
f.close()
Upvotes: 1