首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用python上传和下载到ftp

问使用python上传和下载到ftp
EN

Stack Overflow用户
提问于 2021-10-22 09:56:32
回答 1查看 151关注 0票数 0

首先,我是一个学习python的新手。我正在尝试使用python将文件上载/下载到服务器。服务器ftp没有域名,但有一个IP地址,即192.168.0.20和端口21我尝试了以下代码,但它给出了很多错误

代码语言:javascript
复制
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()

帮助--我哪里错了?

EN

回答 1

Stack Overflow用户

发布于 2021-10-22 10:06:29

在创建FTP对象之后,您可能需要使用ftp.login()登录到服务器。

你得到了哪些确切的错误?

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69674852

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档