【发布时间】:2021-12-08 23:29:13
【问题描述】:
首先是一个学习python的新手。我正在尝试使用 python 将文件上传/下载到服务器。服务器 ftp 没有域名,只有一个 IP 地址,即 192.168.0.20 和端口 21 我尝试了以下代码,但它给出了很多错误
import ftplib
#FTP server credentials
FTP_HOST = '192.16.0.20'
PORT='21'
FTP_USER = 'ftpuser'
FTP_PASS = 'ftpuser'
# connecting to the FTP server
ftp = ftplib.FTP(FTP_HOST,PORT, FTP_USER, FTP_PASS)
# force UTF-8 encoding
ftp.encoding = "utf-8"
# local file name you want to upload
filename = "test.txt"
with open(filename, "rb") as file:
# use FTP's STOR command to upload the file
ftp.storbinary(f'STOR {filename}', file)
# list current files & directories
ftp.dir()
# quit and close the connection
ftp.quit()
求助-我哪里出错了
【问题讨论】:
-
“它给出了很多错误” 并没有向我们提供有关您遇到的错误的任何信息。我们需要您得到准确的错误信息。
-
你能指定这些错误的样子吗?
-
文件“C:\Users\Josiah\AppData\Local\Programs\Python\Python39\lib\ftplib.py”,第 252 行,在 getresp 中引发 error_perm(resp) ftplib.error_perm: 530 用户无法登录。