python - downloading file using ftp -
python - downloading file using ftp -
i writing python script logged in using ftp , download file.but whenever run script,it says have provided wrong user name or passwd.i inputting right password still unable run script.my code is:
import os,getpass urllib.request import urlopen filename='68544.jpg' password=getpass.getpass('??')
at line below script failed run , whenever run address in browser runs fine.
remoteaddr='ftp://kamal:%s@localhost/%s;type=i'%(password,filename) remotefile=urlopen(remoteaddr) localfile=open(filename,'wb') localfile.write(remotefile.read()) localfile.close() remotefile.close()
def ftp_connect(path): link = ftp(host = 'example.com', timeout = 5) #keep low timeout link.login(passwd = 'ftppass', user = 'ftpuser') debug("%s - connected ftp" % strftime("%d-%m-%y %h.%m")) link.cwd(path) homecoming link downloaded = open('/local/path/to/file.tgz', 'wb') def debug(txt): print txt link = ftp_connect(path) file_size = link.size(filename) max_attempts = 5 #i dont want death loops. while file_size != downloaded.tell(): try: debug("%s while > try, run retrbinary\n" % strftime("%d-%m-%y %h.%m")) if downloaded.tell() != 0: link.retrbinary('retr ' + filename, downloaded.write, downloaded.tell()) else: link.retrbinary('retr ' + filename, downloaded.write) except exception myerror: if max_attempts != 0: debug("%s while > except, going wrong: %s\n \tfile lenght is: %i > %i\n"(strftime("%d-%m-%y %h.%m"), myerror, file_size, downloaded.tell())) link = ftp_connect(path) max_attempts -= 1 else: break debug("done file, effort download m5dsum")
[...]
python ftp
Comments
Post a Comment