简体   繁体   English

使用 Python ftplib 上传文件时出现“不允许操作”或“不是常规文件”

[英]Getting “Operation not permitted” or “Not a regular file” when uploading file with Python ftplib

I'm want to upload a file using Python to an rental FTP server (coreserver).我想使用 Python 将文件上传到租用的 FTP 服务器(核心服务器)。 The code is like this代码是这样的

# -*- 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)

but error happens like this但错误是这样发生的

error_perm: 550 /public_html/example.com/: Operation not permitted

I tried我试过了

STOR /public_html/
STOR /public_html
STOR /public_html/example.com/
STOR /public_html/example.com
STOR /example.com/
STOR /example.com

but the error happens all the time但错误总是发生

error_perm: 550 /public_html/example.com/: Operation not permitted

or或者

error_perm: 550 /public_html/example.com/: Not a regular file

Can anybody help me to solve this problem?有人可以帮我解决这个问题吗?

The path in FTP.storbinary argument is the path to the target file, not only to the destination folder. FTP.storbinary参数中的路径是目标文件的路径,而不仅仅是目标文件夹的路径。 How else would ftplib know the name of the file you are uploading? ftplib 怎么知道你上传的文件的名称?

So it should be:所以应该是:

upload_dst_path = "STOR /public_html/xxxxxxx.com/DSC_0569.JPG"

Turns out C# doesn't support CWD command <=4.0, and the solutionMmicrosoft gave was a function named SetMethodRequiresCWD() which gives a NullReferenceException.结果 C# 不支持 CWD 命令 <=4.0,而 Mmicrosoft 给出的解决方案是一个名为 SetMethodRequiresCWD() 的 function,它给出了 NullReferenceException。 So i had to use a custom library named AlexFTPS, here is the code:所以我不得不使用一个名为 AlexFTPS 的自定义库,代码如下:

FTPSClient client = new FTPSClient())
{
client.Connect(host,
new NetworkCredential(username, password), 
ESSLSupportMode.ClearText //For without SSL/TSL
);
client.SetCurrentDirectory("usbfolder");
client.PutFile(filePath,fileName); // "C:/file.txt" and "file.txt", for example
}

I'm putting this here in hope that nobody else goes through this pain.我把它放在这里是希望没有其他人经历这种痛苦。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 Python ftplib 上传文件时,“&#39;NoneType&#39; 对象没有属性 &#39;sendall&#39;” - "'NoneType' object has no attribute 'sendall'" when uploading file with Python ftplib 使用 Python ftplib 上传时如何保留文件 mtime - How to preserve file mtime when uploading with Python ftplib 尝试使用 FTP_TLS 从同一目录下载第二个文件时出现“ftplib.error_perm: 550 Operation not allowed” - "ftplib.error_perm: 550 Operation not permitted" when trying to download the second file from the same directory using FTP_TLS 在 Python 中使用 ftplib 将文件传输到 FTP 服务器时出现“连接被拒绝” - Getting "Connection refused" when transferring a file to FTP server with ftplib in Python 在 Mac 上的 python 中创建一个新的 .py 文件但得到 [Errno 1] 不允许操作 - Creating a new .py file in python on a mac but getting [Errno 1] Operation not permitted 使用 Python ftplib 上传文件时出现“553 Can't open that file: No such file or directory” - "553 Can't open that file: No such file or directory" when uploading a file using Python ftplib 无法通过FTPLIB和Python上传文件时出现文件错误 - Can't open file error uploading file via FTPLIB and Python EOFError-使用ftplib上传.csv文件 - EOFError - Uploading .csv file using ftplib 获取 chown():从 ini 文件运行 uwsgi 时不允许操作 - Getting chown(): Operation not permitted while running uwsgi from ini file Python ftplib文件open()TypeError - Python ftplib file open() TypeError
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM