Got this FTP upload code. This example has the correct data so you can try it.
The path is correct since I got it from select box (filename = askopenfilename()
)
I get:
ftplib.error_perm: 553 Can't open that file: No such file or directory
I get error here:
cmd 'STOR /Users/rs/Desktop/DESKTOP/fields.png'
put 'STOR /Users/rs/Desktop/DESKTOP/fields.png\r\n'
import ftplib
from tkinter import Tk
from tkinter.filedialog import askopenfilename
import urllib
Tk().withdraw()
filename = askopenfilename()
print(filename)
from ftplib import FTP
import os
import fileinput
ftp = FTP()
ftp.set_debuglevel(2)
ftp.connect('ftpupload.net', 21)
ftp.login('ezyro_28887012', 'ricardo123456')
ftp.encoding = "utf-8"
print("List Dir: ",ftp.dir())
print("filename: ",filename)
with open(filename, "rb") as file:
ftp.storbinary(f"STOR {filename}", file)
# Get list of files
print("NEW DIR AFTER UPLOAD: ",ftp.dir())
# Close the Connection
ftp.quit()
Can someone help?
/usr/local/bin/python3.9 /Users/rs/PycharmProjects/OCPP/ftpconf.py
/Users/rs/Desktop/DESKTOP/issue fields.png
*get* '220---------- Welcome to Pure-FTPd [privsep] [TLS] ----------\n'
*get* '220-You are user number 292 of 6900 allowed.\n'
*get* '220-Local time is now 08:51. Server port: 21.\n'
*get* '220-This is a private system - No anonymous login\n'
*get* '220 You will be disconnected after 60 seconds of inactivity.\n'
*resp* '220---------- Welcome to Pure-FTPd [privsep] [TLS] ----------\n220-You are user number 292 of 6900 allowed.\n220-Local time is now 08:51. Server port: 21.\n220-This is a private system - No anonymous login\n220 You will be disconnected after 60 seconds of inactivity.'
*cmd* 'USER ezyro_28887012'
*put* 'USER ezyro_28887012\r\n'
*get* '331 User ezyro_28887012 OK. Password required\n'
*resp* '331 User ezyro_28887012 OK. Password required'
*cmd* 'PASS *************'
*put* 'PASS *************\r\n'
*get* '230-Your bandwidth usage is restricted\n'
*get* '230 OK. Current restricted directory is /\n'
*resp* '230-Your bandwidth usage is restricted\n230 OK. Current restricted directory is /'
*cmd* 'TYPE A'
*put* 'TYPE A\r\n'
*get* '200 TYPE is now ASCII\n'
*resp* '200 TYPE is now ASCII'
*cmd* 'PASV'
*put* 'PASV\r\n'
*get* '227 Entering Passive Mode (185,27,134,11,171,227)\n'
*resp* '227 Entering Passive Mode (185,27,134,11,171,227)'
*cmd* 'LIST htdocs'
*put* 'LIST htdocs\r\n'
*get* '150 Accepted data connection\n'
*resp* '150 Accepted data connection'
drwxr-xr-x 2 28887012 28887012 108 Aug 13 08:47 .
drwxr-xr-x 3 0 0 106 Jun 15 05:39 ..
-rw-r--r-- 1 28887012 28887012 49619 Jul 27 10:32 210727_logs_16040279_10566_3.4.2.zip
-rw-r--r-- 1 28887012 28887012 8695466 Jul 27 06:17 ECP_ISO_3.4.2.7z
-rw-r--r-- 1 28887012 28887012 229 Jun 30 07:46 index.html
*get* '226-Options: -a -l \n'
*get* '226 5 matches total\n'
*resp* '226-Options: -a -l \n226 5 matches total'
*cmd* 'TYPE A'
*put* 'TYPE A\r\n'
*get* '200 TYPE is now ASCII\n'
*resp* '200 TYPE is now ASCII'
*cmd* 'PASV'
*put* 'PASV\r\n'
*get* '227 Entering Passive Mode (185,27,134,11,112,120)\n'
*resp* '227 Entering Passive Mode (185,27,134,11,112,120)'
*cmd* 'LIST'
*put* 'LIST\r\n'
*get* '150 Accepted data connection\n'
*resp* '150 Accepted data connection'
drwxr-xr-x 3 0 0 106 Jun 15 05:39 .
drwxr-xr-x 3 0 0 106 Jun 15 05:39 ..
-r--r--r-- 1 0 0 90 Jun 15 05:39 .htaccess
-rw-r--r-- 1 0 2 0 Jun 15 05:39 .override
-rw-r--r-- 1 0 2 0 Jun 15 05:39 DO NOT UPLOAD FILES HERE
drwxr-xr-x 2 28887012 28887012 108 Aug 13 08:47 htdocs
*get* '226-Options: -a -l \n'
*get* '226 6 matches total\n'
*resp* '226-Options: -a -l \n226 6 matches total'
List Dir: None
--------> <_io.BufferedReader name='/Users/rs/Desktop/DESKTOP/issue fields.png'>
-aaaaaaaaaaaaa---> /Users/rs/Desktop/DESKTOP/issue fields.png
*cmd* 'TYPE I'
*put* 'TYPE I\r\n'
*get* '200 TYPE is now 8-bit binary\n'
*resp* '200 TYPE is now 8-bit binary'
*cmd* 'PASV'
*put* 'PASV\r\n'
*get* '227 Entering Passive Mode (185,27,134,11,228,17)\n'
*resp* '227 Entering Passive Mode (185,27,134,11,228,17)'
*cmd* 'STOR /Users/rs/Desktop/DESKTOP/issue fields.png'
*put* 'STOR /Users/rs/Desktop/DESKTOP/issue fields.png\r\n'
Traceback (most recent call last):
File "/Users/rs/PycharmProjects/OCPP/ftpconf.py", line 32, in <module>
ftp.storbinary(f"STOR {filename}", file)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/ftplib.py", line 498, in storbinary
with self.transfercmd(cmd, rest) as conn:
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/ftplib.py", line 393, in transfercmd
return self.ntransfercmd(cmd, rest)[0]
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/ftplib.py", line 359, in ntransfercmd
resp = self.sendcmd(cmd)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/ftplib.py", line 281, in sendcmd
return self.getresp()
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/ftplib.py", line 254, in getresp
raise error_perm(resp)
ftplib.error_perm: 553 Can't open that file: No such file or directory
*get* "553 Can't open that file: No such file or directory\n"
*resp* "553 Can't open that file: No such file or directory"
Process finished with exit code 1
You are trying to save the file on the remote server using a local path. Note how you use the same path with local open
and remote storbinary
. I'm quite sure your remote server has a different directory structure.
If you want to upload the file to your FTP home directory, use just a filename:
ftp.storbinary("STOR " + os.path.basename(filename), file)
If you want to upload to a specific folder, use real path on your FTP server, like:
ftp.storbinary("STOR htdocs/" + os.path.basename(filename), file)