[Python] Upload a file to FTP over TLS with Python is failing with "[Errno 10054] An existing...

Discussão em 'Python' iniciado por Stack, Junho 26, 2025.

  1. Stack

    Stack Membro Participativo

    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
    ​

    I get the error on the line

    ftps.storbinary("STOR " + output_file_name,open(output_file,'rb'))


    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?

    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.

    Continue reading...

Compartilhe esta Página