From 51859af8d95dcfd50c242f08f11ad560ba5b32b3 Mon Sep 17 00:00:00 2001 From: dougal <147946567+roucc@users.noreply.github.com> Date: Fri, 24 Oct 2025 14:50:13 +0100 Subject: [PATCH] ftp: fix SOCK proxy support - fixes #8892 (#8918) --- backend/ftp/ftp.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/backend/ftp/ftp.go b/backend/ftp/ftp.go index 2c0617911..d2b3c5fa3 100644 --- a/backend/ftp/ftp.go +++ b/backend/ftp/ftp.go @@ -456,9 +456,7 @@ func (f *Fs) ftpConnection(ctx context.Context) (c *ftp.ServerConn, err error) { } }() baseDialer := fshttp.NewDialer(ctx) - if f.opt.SocksProxy != "" { - conn, err = proxy.SOCKS5Dial(network, address, f.opt.SocksProxy, baseDialer) - } else if f.proxyURL != nil { + if f.opt.SocksProxy != "" || f.proxyURL != nil { // We need to make the onward connection to f.opt.Host. However the FTP // library sets the host to the proxy IP after using EPSV or PASV so we need // to correct that here. @@ -468,7 +466,11 @@ func (f *Fs) ftpConnection(ctx context.Context) (c *ftp.ServerConn, err error) { return nil, err } dialAddress := net.JoinHostPort(f.opt.Host, dialPort) - conn, err = proxy.HTTPConnectDial(network, dialAddress, f.proxyURL, baseDialer) + if f.opt.SocksProxy != "" { + conn, err = proxy.SOCKS5Dial(network, dialAddress, f.opt.SocksProxy, baseDialer) + } else { + conn, err = proxy.HTTPConnectDial(network, dialAddress, f.proxyURL, baseDialer) + } } else { conn, err = baseDialer.Dial(network, address) }