gpt4 book ai didi

Python FTPLIB 错误 530 权限被拒绝

转载 作者:太空宇宙 更新时间:2023-11-04 06:12:47 24 4
gpt4 key购买 nike

我试过下面的脚本:

import os
from 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 the 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()

但每次我运行脚本时,它都会说:

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.

我不知道 530 Permission Denied 是什么意思。谁能告诉我这是什么意思?

最佳答案

  • 似乎 ftp 服务器允许匿名访问;您不需要传递用户名和密码。
  • FTP 构造函数接受主机名(或 IP),而不是 URL。

import sys
import os
from 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 the file
with open(os.path.join(r"c:\example", filename), 'wb') as f:
ftp.retrbinary("RETR " + filename, VerboseWriter(lf, filesize).write, 8*1024)
print
ftp.quit()

关于Python FTPLIB 错误 530 权限被拒绝,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17780644/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com