Last active
May 18, 2024 01:14
-
-
Save jnimety/01c63faea799385862100b5a16b013d8 to your computer and use it in GitHub Desktop.
Ruby Net::FTP Implicit TLS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Assumes a recent version of ruby with TLS and Explicit TLS support | |
class ImplicitTlsFTP < Net::FTP | |
FTP_PORT = 990 | |
def connect(host, port = FTP_PORT) | |
synchronize do | |
@host = host | |
@bare_sock = open_socket(host, port) | |
begin | |
ssl_sock = start_tls_session(Socket.tcp(host, port)) | |
@sock = BufferedSSLSocket.new(ssl_sock, read_timeout: @read_timeout) | |
voidresp | |
if @private_data_connection | |
voidcmd("PBSZ 0") | |
voidcmd("PROT P") | |
end | |
rescue OpenSSL::SSL::SSLError, Net::OpenTimeout | |
@sock.close | |
raise | |
end | |
end | |
end | |
end | |
ImplicitTlsFTP.open(host, ssl: true) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thats really helpfull, somehow still in 2024 some ftp servers with implicit tls timeout any request in nonSSL socker, thats why default voidresp hangs out (in common net/ftp connect it goes beforre
begin
)