Skip to content

Instantly share code, notes, and snippets.

@jnimety
Last active May 18, 2024 01:14
Show Gist options
  • Save jnimety/01c63faea799385862100b5a16b013d8 to your computer and use it in GitHub Desktop.
Save jnimety/01c63faea799385862100b5a16b013d8 to your computer and use it in GitHub Desktop.
Ruby Net::FTP Implicit TLS
# 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)
@foxeg
Copy link

foxeg commented May 18, 2024

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment