1

I'm trying to establish a connection with a FTP server using ftplib. I received two files, a certificate with .crt extension and a certificate in PEM format (RSA KEY + Certificate).

I'm using the certificate in PEM format to create a context using the following code:

import ssl
from ftplib import FTP_TLS

ssl_context = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
ssl_context.load_cert_chain('./certificate3') 
ftps = FTP_TLS(context = ssl_context)
ftps.connect(host, porta)
ftps.login(user = user, passwd = pwd)
ftps.prot_p()
ftps.nlst()

If I remove the last command (nlst) I receive the response: '230 Logged on'. Therefore when I try to extract list of documents inside the FTP with nlst() command I receive an error message:

TimeoutError: [WinError 10060] A connection attempt failed because the connected component did not respond
correctly after a period of time or the established connection has failed
because the connected host did not respond

Does anybody know what is wrong and how to fix the code in order to establish the connection?

1
  • Can you ist the directory contents with enabled SSL using any GUI/commandline FTP client running on the same machine as your Python code? Oct 29, 2020 at 20:54

1 Answer 1

0

I could establish connection to FTP server with WinSCP. Through WinSCP I can run an script to synchronize the server with my local directory. Below you can find the command:

option batch abort
option confirm off
open ftp://user:password@hostserver:port -hostkey="SHA256 KEY"
synchronize local local_path remote_path
exit

This command must be in .txt file, and through a .bat file this command is executed.

Hope I can help other with the same issue.

4
  • This WinSCP script does not use encryption/SSL (unless you have a stored site in WinSCP with enabled SSL with name ftp://user:password@hostserver:port – what seems implausible) + -hostkey has no effect with ftp:// sessions. Oct 29, 2020 at 20:53
  • I tried different ways to establish connection with SSL with no success. Unfortunately, nobody in the community answered my question. I identified this way (WINSCP) that worked for me and for this reason I answered my own question to share with community this alternative way. If you know how to establish using ftplib and SSL I appreciate if you can help me as well.
    – danimille
    Oct 30, 2020 at 11:25
  • I do not think you have answered you own question. I believe you had problems with ftplib because of the SSL. If you have chosen to give up on security as a workaround, I'm quite sure that ftplib would work to without SSL. There's probably no reason to give up on SSL AND switch FTP client at the same time. Not that I mind that you chose my WinSCP :) Oct 30, 2020 at 11:36
  • Once you don't mind, I'll keep using your winscp instead of ftplib =)
    – danimille
    Oct 30, 2020 at 11:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.