0
votes

I receive the following error when uploading a small text file to an ftp site when using python's ftplib:

      File "ftpuploader.py", line 13, in uploadFilePath
    ftp.storbinary("STOR {}".format(filepath), file)
  File "/usr/lib64/python2.7/ftplib.py", line 471, in storbinary
    conn = self.transfercmd(cmd, rest)
  File "/usr/lib64/python2.7/ftplib.py", line 376, in transfercmd
    return self.ntransfercmd(cmd, rest)[0]
  File "/usr/lib64/python2.7/ftplib.py", line 358, in ntransfercmd
    resp = self.sendcmd(cmd)
  File "/usr/lib64/python2.7/ftplib.py", line 249, in sendcmd
    return self.getresp()
  File "/usr/lib64/python2.7/ftplib.py", line 224, in getresp
    raise error_perm, resp
ftplib.error_perm: 553 Could not create file.

I am using the following code successfully when connecting to another system. I can log in, change directories, but am unable to create the file. I can load a file using either filezilla or a simple curl command, curl -T '/path/to/file' ftp://192.168.18.75 --user admin:password

ftp = FTP(address)
ftp.login(username, password)
ftp.cwd('/gui')
file = open(filepath, 'rb')
ftp.storbinary("STOR {}".format(filepath), file)
ftp.retrlines('LIST') # list directory contents     
file.close()
ftp.quit()

any ideas?

1

1 Answers

2
votes

You are passing a path to a local path to the STOR command (the same path you use with the open(filepath, 'rb')).

While with the CURL, you do not specify any path to the remote file. So the file gets uploaded to the current FTP working directory.

As already suggested in the comments by @acw1668, use the:

ftp.storbinary("STOR {}".format(os.path.basename(filepath)), file)