2

I'm want to upload a file using Python to an rental FTP server (coreserver). 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?

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
Kiyo4810
  • 21
  • 2

2 Answers2

1

The path in FTP.storbinary argument is the path to the target file, not only to the destination folder. How else would ftplib know the name of the file you are uploading?

So it should be:

upload_dst_path = "STOR /public_html/xxxxxxx.com/DSC_0569.JPG"
Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
-1

Turns out C# doesn't support CWD command <=4.0, and the solutionMmicrosoft gave was a function named SetMethodRequiresCWD() which gives a NullReferenceException. So i had to use a custom library named AlexFTPS, here is the code:

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.

pro hacker
  • 31
  • 3