download - Python FTPLIB error 530 Permission Denied -


i've tried script below:

import os ftplib import ftp  ftp = ftp("ftpsite","myuser", "mypass") ftp.login() ftp.retrlines("list")  ftp.cwd("folderone") ftp.cwd("subfolder")  listing = [] ftp.retrlines("list", listing.append) words = listing[0].split(none, 8) filename = words[-1].lstrip()  #download file local_filename = os.path.join(r"c:\example", file) lf = open(local_filename, "wb") ftp.retrbinary("retr " + filename, lf.write, 8*1024) lf.close() 

but everytime run script, says:

traceback (most recent call last):   file "c:\user\desktop\sample\ex.py", line 4, in <module>     ftp = ftp("ftpsite", "myuser", "mypass")   file "c:\python27\lib\ftplib.py", line 119, in __init__     self.login(user, passwd, acct)   file "c:\python27\lib\ftplib.py", line 387, in login     resp = self.sendcmd('user ' + user)   file "c:\python27\lib\ftplib.py", line 244, in sendcmd     return self.getresp()   file "c:\python27\lib\ftplib.py", line 219, in getresp     raise error_perm, resp error_perm: 530 permission denied. 

i don't know 530 permission denied means.can tell me means?

  • it seems ftp server allows anonymous access; don't need pass username, password.
  • ftp constructor accept hostname(or ip), not url.

import sys import os ftplib import ftp  ftp = ftp("ftpsite.com") ftp.login() ftp.cwd("/ftp/site/directory/")  listing = [] ftp.retrlines("list", listing.append) words = listing[0].split(none, 8) filesize = int(words[4]) filename = words[-1].lstrip()  class verbosewriter:     def __init__(self, lf, filesize):         self.progress = 0         self.lf = lf         self.filesize = filesize     def write(self, data):         self.lf.write(data)         self.progress += len(data)         sys.stdout.write('\r{}/{} ({:.1%})'.format(self.progress, self.filesize, float(self.progress)/self.filesize))         sys.stdout.flush()  #download file open(os.path.join(r"c:\example", filename), 'wb') f:     ftp.retrbinary("retr " + filename, verbosewriter(lf, filesize).write, 8*1024) print ftp.quit() 

Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

c# - must be a non-abstract type with a public parameterless constructor in redis -

ajax - PHP/JSON Login script (Twitter style) not setting sessions -