How to download a file via FTP with Python ftplib
handle = open(path.rstrip("/") + "/" + filename.lstrip("/"), 'wb')
ftp.retrbinary('RETR %s' % filename, handle.write)
A = filename
ftp = ftplib.FTP("IP")
ftp.login("USR Name", "Pass")
ftp.cwd("/Dir")
try:
ftp.retrbinary("RETR " + filename ,open(A, 'wb').write)
except:
print "Error"
FILENAME = 'StarWars.avi'
with ftplib.FTP(FTP_IP, FTP_LOGIN, FTP_PASSWD) as ftp:
ftp.cwd('movies')
with open(FILENAME, 'wb') as f:
ftp.retrbinary('RETR ' + FILENAME, f.write)
Of course it would we be wise to handle possible errors.