[英]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.