python - 使用 Python ftplib 上传文件时出现“不允许操作”或“不是常规文件”
问题描述
我想使用 Python 将文件上传到租用的 FTP 服务器(coreserver)。代码是这样的
# -*- coding: utf-8 -*-
import ftplib
def ftp_upload(hostname, username, password, upload_src_path, upload_dst_path):
ftp = ftplib.FTP(hostname)
ftp.set_pasv("true")
ftp.login(username, password)
fp = open(upload_src_path, 'rb')
ftp.storbinary(upload_dst_path ,fp)
ftp.close()
fp.close()
hostname = "example.com"
upload_src_path = "/content/drive/My Drive/DSC_0569.JPG"
upload_dst_path = "STOR /public_html/example.com/"
username = "example"
password = "example"
ftp_upload(hostname, username, password, upload_src_path, upload_dst_path)
但错误是这样发生的
error_perm: 550 /public_html/example.com/: Operation not permitted
我试过了
STOR /public_html/
STOR /public_html
STOR /public_html/example.com/
STOR /public_html/example.com
STOR /example.com/
STOR /example.com
但错误总是发生
error_perm: 550 /public_html/example.com/: Operation not permitted
或者
error_perm: 550 /public_html/example.com/: Not a regular file
有人可以帮我解决这个问题吗?
解决方案
参数中的路径FTP.storbinary
是目标文件的路径,而不仅仅是目标文件夹的路径。ftplib 怎么知道你上传的文件的名称?
所以应该是:
upload_dst_path = "STOR /public_html/xxxxxxx.com/DSC_0569.JPG"
推荐阅读
- javascript - 由于某种原因,我的导航栏有滚动条?
- mongodb - Kafka 主题返回 0 条消息
- css - 我的 css 文件太大,因为 url-loader 正在将 .jpg 代码插入到 .css 文件中 - 如何配置 webpack 使其指向 img?
- c# - Tweetinvi 5.0 获取推文回复
- git - 使用 git clone 从 github 下载大型 lfs 文件时出现问题
- java - 如何在 Firestore 中构建关注系统
- c# - 未找到 Xamarin 绑定属性
- javascript - Firestore 功能云消息传递无法正常工作
- python-3.x - matplotlib 子图自动缩小
- javascript - 在节点应用程序中使用 SocketIO 跨路由/页面发送数据