I’m trying to make Python uploading files on a FTP server. The code is following:
... ## setting values to variables: ftp_site, ftp_port, ftp_user, ftp_pwd, output_file_name, output_file
import ftplib
ftps = ftplib.FTP_TLS()
ftps.connect(ftp_site,ftp_port)
ftps.auth()
ftps.login(ftp_user,ftp_pwd)
ftps.prot_p()
ftps.storbinary("STOR " + output_file_name,open(output_file,'rb'))
ftps.quit()
It used to work fine earlier, but now I get the following error:
error: [Errno 10054] An existing connection was forcibly closed by the remote host
The Python version is 2.7. I’ve been looking through similar topics but nothing helps. Could anyone tell how to make it work please?
Thanks!
upd: I get the error on the line
ftps.storbinary("STOR " + output_file_name,open(output_file,'rb'))
I can upload a file from this machine to the server using through TCM/FileZilla. Moreover, I can rename a file on the server using Python with this command:
ftps.rename('a.txt', 'b.txt')
So that’s not an access issue
I think the issue lies in that you are trying to connect to an insecure FTP server using FTP over TLS. The code you provided has been tested with an insecure FTP server over port 21, and the same exact error is thrown. If that’s the case, please try using instead the below. Please note, the below establishes an insecure connection between you and the FTP server.