Post a reply

Before posting, please read how to report bug or request support effectively.

Bug reports without an attached log file are usually useless.

Options
Add an Attachment

If you do not want to add an Attachment to your Post, please leave the Fields blank.

(maximum 10 MB; please compress large files; only common media, archive, text and programming file formats are allowed)

Options

Topic review

martin

Re: Access to the FTP server via an SSH tunnel is not working

As I have written above, dynamic port forwarding works as a SOCKS proxy. So you need to configure it as a SOCKS proxy in WinSCP.
kuzyaka

Re: Access to the FTP server via an SSH tunnel is not working

I tried to connect via dynamic port 5534.
ssh-server=192.168.0.1

ftp-server=192.168.0.2

But it doesn't work either.
Using scPulkovo As New SshClient(ciPulkovo)
  Try
    scPulkovo.Connect()
    If scPulkovo.IsConnected Then
      If ПроверкаНаличияСервераTelnet("192.168.0.2", 21) Then
        Dim portDynamic As New ForwardedPortDynamic(5534)
        scPulkovo.AddForwardedPort(portDynamic)
        portDynamic.Start()
 
        If portDynamic.IsStarted Then
          Dim ProcessWinSCP As New Process
          ProcessWinSCP.StartInfo.FileName = "WinSCP.exe"
          ProcessWinSCP.StartInfo.Arguments = "/ini=nul /log=ftp.log ftp://data:030562@localhost:21/"
          ProcessWinSCP.Start()
          ProcessWinSCP.WaitForExit()
          ProcessWinSCP.Close()
          portDynamic .Stop()
        Else
          MessageBox.Show("Ошибка при создании туннеля!",
                                      "WinSCP",
                                      MessageBoxButtons.OK,
                                      MessageBoxIcon.Error)
        End If
        scPulkovo.RemoveForwardedPort(portDynamic)
      End If
    End If
  Catch ex1 As Exception
    MessageBox.Show("Ошибка при создании туннеля!" & vbCrLf & ex1.Message,
                          "WinSCP",
                          MessageBoxButtons.OK,
                          MessageBoxIcon.Error)
  End Try
End Using

. 2025-08-25 16:34:22.436 --------------------------------------------------------------------------
. 2025-08-25 16:34:22.438 WinSCP Версия 6.5.3 (Сборка 16364 2025-07-16) (OS 10.0.26100 – Windows 11 Pro)
. 2025-08-25 16:34:22.438 Configuration: nul
. 2025-08-25 16:34:22.440 Log level: Normal
. 2025-08-25 16:34:22.440 Local account: ALEXHOME\User
. 2025-08-25 16:34:22.440 Working directory: F:\Документы\Visual Studio Projects\Цветы\Инструменты\УдаленныйДоступ\УдаленныйДоступ\bin\Debug
. 2025-08-25 16:34:22.440 Process ID: 26548
. 2025-08-25 16:34:22.457 Ancestor processes: RemoteDesktop, msvsmon, devenv, ...
. 2025-08-25 16:34:22.457 Command-line: "F:\Документы\Visual Studio Projects\Цветы\Инструменты\УдаленныйДоступ\УдаленныйДоступ\bin\Debug\WinSCP.exe" /ini=nul /log=ftp.log ftp://data:***@localhost:21/ -rawsettings ProxyMethod=2 ProxyPort=5534
. 2025-08-25 16:34:22.457 Time zone: Current: GMT+3 (RTZ 2 (зима)), No DST
. 2025-08-25 16:34:22.459 Login time: 25 Август 2025 г. 16:34:22
. 2025-08-25 16:34:22.459 --------------------------------------------------------------------------
. 2025-08-25 16:34:22.459 Session name: data@localhost (Ad-Hoc site)
. 2025-08-25 16:34:22.459 Host name: localhost (Port: 21)
. 2025-08-25 16:34:22.459 User name: data (Password: Yes, Key file: No, Passphrase: No)
. 2025-08-25 16:34:22.459 Transfer Protocol: FTP
. 2025-08-25 16:34:22.459 Ping type: Dummy, Ping interval: 30 sec; Timeout: 15 sec
. 2025-08-25 16:34:22.459 Disable Nagle: No
. 2025-08-25 16:34:22.459 Proxy: SOCKS5
. 2025-08-25 16:34:22.459 HostName: proxy (Port: 5534); Username: ; Passwd: No
. 2025-08-25 16:34:22.459 Send buffer: 262144
. 2025-08-25 16:34:22.459 UTF: Auto
. 2025-08-25 16:34:22.459 FTPS: None [Client certificate: No]
. 2025-08-25 16:34:22.459 FTP: Passive: Yes [Force IP: Auto]; MLSD: Auto [List all: Auto]; HOST: Auto
. 2025-08-25 16:34:22.459 Local directory: default, Remote directory: home, Update: Yes, Cache: Yes
. 2025-08-25 16:34:22.459 Cache directory changes: Yes, Permanent: Yes
. 2025-08-25 16:34:22.459 Recycle bin: Delete to: No, Overwritten to: No, Bin path:
. 2025-08-25 16:34:22.459 Timezone offset: 0h 0m
. 2025-08-25 16:34:22.459 --------------------------------------------------------------------------
. 2025-08-25 16:34:22.889 Соединяюсь с localhost…
. 2025-08-25 16:34:25.197 Не получается соединиться.
* 2025-08-25 16:34:25.237 (EFatal) Не получается соединиться.
* 2025-08-25 16:34:25.237 Не получается соединиться.

Maybe I made a mistake somewhere?
kuzyaka

Re: Access to the FTP server via an SSH tunnel is not working

I create an SSH Tunnel like this
Using scPulkovo As New SshClient(ciPulkovo)
  Try
    scPulkovo.Connect()
    If scPulkovo.IsConnected Then
      If ПроверкаНаличияСервераTelnet("192.168.0.2", 21) Then
        Dim pflFTP As New ForwardedPortLocal("127.0.0.1", 21, "192.168.0.2", 21)
        scPulkovo.AddForwardedPort(pflFTP)
        pflFTP.Start()
        If pflFTP.IsStarted Then
          Dim ProcessWinSCP As New Process
          ProcessWinSCP.StartInfo.FileName = "WinSCP.exe"
          ProcessWinSCP.StartInfo.Arguments = "/ini=nul /log=ftp.log ftp://data:030562@localhost:21/"
          ProcessWinSCP.Start()
          ProcessWinSCP.WaitForExit()
          ProcessWinSCP.Close()
          pflFTP.Stop()
        Else
          MessageBox.Show("Ошибка при создании туннеля!",
                                    "WinSCP",
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Error)
        End If
        scPulkovo.RemoveForwardedPort(pflFTP)
      End If
    End If
  Catch ex1 As Exception
    MessageBox.Show("Ошибка при создании туннеля!" & vbCrLf & ex1.Message,
                          "WinSCP",
                          MessageBoxButtons.OK,
                          MessageBoxIcon.Error)
  End Try
End Using
martin

Re: Access to the FTP server via an SSH tunnel is not working

Indeed, FTP session uses different connection and port for file transfers and directory listings. So tunneling it through SSH is not that trivial.

Or does it work with any other FTP client? I guess it does not, right? I believe this is not a WinSCP question at all.

How are you creating the tunnel? I believe that for example PuTTY's dynamic port forwarding feature that creates SOCKS proxy can be used for this purpose.
kuzyaka62

Access to the FTP server via an SSH tunnel is not working

Access to the FTP server via an SSH tunnel is not working.
An error appears when trying to read the directory on the server.
425 Unable to build data connection: EINVAL - Invalid argument passed

. 2025-08-21 14:57:47.916 --------------------------------------------------------------------------
. 2025-08-21 14:57:47.919 WinSCP Версия 6.5.3 (Сборка 16364 2025-07-16) (OS 10.0.26100 – Windows 11 Pro)
. 2025-08-21 14:57:47.919 Configuration: nul
. 2025-08-21 14:57:47.919 Log level: Normal
. 2025-08-21 14:57:47.919 Local account: ALEXHOME\User
. 2025-08-21 14:57:47.919 Working directory: F:\Документы\Visual Studio Projects\Цветы\Инструменты\УдаленныйДоступ\УдаленныйДоступ\bin\Release
. 2025-08-21 14:57:47.919 Process ID: 7616
. 2025-08-21 14:57:47.937 Ancestor processes: RemoteDesktop, msvsmon, devenv, ...
. 2025-08-21 14:57:47.937 Command-line: "F:\Документы\Visual Studio Projects\Цветы\Инструменты\УдаленныйДоступ\УдаленныйДоступ\bin\Release\WinSCP.exe" /ini=nul /log=ftp.log ftp://user:***@localhost:21/
. 2025-08-21 14:57:47.937 Time zone: Current: GMT+3 (RTZ 2 (зима)), No DST
. 2025-08-21 14:57:47.938 Login time: 21 Август 2025 г. 14:57:47
. 2025-08-21 14:57:47.938 --------------------------------------------------------------------------
. 2025-08-21 14:57:47.938 Session name: user@localhost (Ad-Hoc site)
. 2025-08-21 14:57:47.938 Host name: localhost (Port: 21)
. 2025-08-21 14:57:47.938 User name: user (Password: Yes, Key file: No, Passphrase: No)
. 2025-08-21 14:57:47.938 Transfer Protocol: FTP
. 2025-08-21 14:57:47.938 Ping type: Dummy, Ping interval: 30 sec; Timeout: 15 sec
. 2025-08-21 14:57:47.938 Disable Nagle: No
. 2025-08-21 14:57:47.938 Proxy: None
. 2025-08-21 14:57:47.938 Send buffer: 262144
. 2025-08-21 14:57:47.938 UTF: Auto
. 2025-08-21 14:57:47.938 FTPS: None [Client certificate: No]
. 2025-08-21 14:57:47.938 FTP: Passive: Yes [Force IP: Auto]; MLSD: Auto [List all: Auto]; HOST: Auto
. 2025-08-21 14:57:47.938 Local directory: default, Remote directory: home, Update: Yes, Cache: Yes
. 2025-08-21 14:57:47.938 Cache directory changes: Yes, Permanent: Yes
. 2025-08-21 14:57:47.938 Recycle bin: Delete to: No, Overwritten to: No, Bin path:
. 2025-08-21 14:57:47.938 Timezone offset: 0h 0m
. 2025-08-21 14:57:47.938 --------------------------------------------------------------------------
. 2025-08-21 14:57:48.440 Соединяюсь с localhost…
. 2025-08-21 14:57:50.004 Соединение с localhost установлено. Ожидаю приветствие…
< 2025-08-21 14:57:50.050 220-FileZilla Server 1.8.1
< 2025-08-21 14:57:50.050 220 Please visit https://filezilla-project.org/
> 2025-08-21 14:57:50.050 USER user
< 2025-08-21 14:57:50.053 331 Please, specify the password.
> 2025-08-21 14:57:50.053 PASS ******
< 2025-08-21 14:57:50.056 230 Login successful.
> 2025-08-21 14:57:50.056 SYST
. 2025-08-21 14:57:50.058 FileZilla server detected.
< 2025-08-21 14:57:50.058 215 UNIX emulated by FileZilla.
> 2025-08-21 14:57:50.058 FEAT
< 2025-08-21 14:57:50.059 211-Features:
< 2025-08-21 14:57:50.059  MDTM
< 2025-08-21 14:57:50.059  REST STREAM
< 2025-08-21 14:57:50.080  SIZE
< 2025-08-21 14:57:50.080  MLST type*;size*;modify*;perm*;
< 2025-08-21 14:57:50.080  MLSD
< 2025-08-21 14:57:50.080  AUTH SSL
< 2025-08-21 14:57:50.080  AUTH TLS
< 2025-08-21 14:57:50.080  PROT
< 2025-08-21 14:57:50.080  PBSZ
< 2025-08-21 14:57:50.080  UTF8
< 2025-08-21 14:57:50.080  TVFS
< 2025-08-21 14:57:50.080  EPSV
< 2025-08-21 14:57:50.080  EPRT
< 2025-08-21 14:57:50.080  MFMT
< 2025-08-21 14:57:50.080 211 End
. 2025-08-21 14:57:50.146 Соединение установлено
. 2025-08-21 14:57:50.146 --------------------------------------------------------------------------
. 2025-08-21 14:57:50.146 Using FTP protocol.
. 2025-08-21 14:57:50.146 Doing startup conversation with host.
> 2025-08-21 14:57:50.163 PWD
< 2025-08-21 14:57:50.166 257 "/" is current directory.
. 2025-08-21 14:57:50.166 Getting current directory name.
. 2025-08-21 14:57:50.206 Получаю содержимое каталога…
> 2025-08-21 14:57:50.206 TYPE A
< 2025-08-21 14:57:50.209 200 Type set to A
> 2025-08-21 14:57:50.209 PASV
< 2025-08-21 14:57:50.212 227 Entering Passive Mode (192,168,0,2,194,246)
> 2025-08-21 14:57:50.212 MLSD
. 2025-08-21 14:57:50.212 Соединяюсь с 192.168.0.2:49910…
. 2025-08-21 14:57:50.213 Data connection closed
. 2025-08-21 14:57:50.214 <Empty directory listing>
< 2025-08-21 14:57:50.215 425 Unable to build data connection: EINVAL - Invalid argument passed
. 2025-08-21 14:57:50.215 Не могу получить содержимое каталога
* 2025-08-21 14:57:50.237 (ECommand) Не могу просмотреть каталог '/'.
* 2025-08-21 14:57:50.237 Не могу получить содержимое каталога
* 2025-08-21 14:57:50.237 Unable to build data connection: EINVAL - Invalid argument passed
. 2025-08-21 14:57:51.543 Startup conversation with host finished.
. 2025-08-21 14:58:21.038 Sending dummy command to keep session alive.
> 2025-08-21 14:58:21.038 TYPE A
< 2025-08-21 14:58:21.038 200 Type set to A
. 2025-08-21 14:58:50.117 Sending dummy command to keep session alive.
> 2025-08-21 14:58:50.117 REST 0
< 2025-08-21 14:58:50.117 350 Restarting at 0

This happens when you connect to the FileZilla FTP server.
It is also not possible to connect to the vsftpd FTP server via an SSH tunnel, but there is another reason:
. 2025-08-21 18:01:29.953 --------------------------------------------------------------------------
. 2025-08-21 18:01:29.955 WinSCP Версия 6.5.3 (Сборка 16364 2025-07-16) (OS 10.0.26100 – Windows 11 Pro)
. 2025-08-21 18:01:29.955 Configuration: nul
. 2025-08-21 18:01:29.955 Log level: Normal
. 2025-08-21 18:01:29.955 Local account: ALEXHOME\User
. 2025-08-21 18:01:29.955 Working directory: F:\Документы\Visual Studio Projects\Цветы\Инструменты\УдаленныйДоступ\УдаленныйДоступ\bin\Debug
. 2025-08-21 18:01:29.955 Process ID: 12204
. 2025-08-21 18:01:29.974 Ancestor processes: RemoteDesktop, msvsmon, devenv, ...
. 2025-08-21 18:01:29.974 Command-line: "F:\Документы\Visual Studio Projects\Цветы\Инструменты\УдаленныйДоступ\УдаленныйДоступ\bin\Debug\WinSCP.exe" /ini=nul /log=ftp.log ftp://anonymous:***@localhost:21/
. 2025-08-21 18:01:29.974 Time zone: Current: GMT+3 (RTZ 2 (зима)), No DST
. 2025-08-21 18:01:29.974 Login time: 21 Август 2025 г. 18:01:29
. 2025-08-21 18:01:29.974 --------------------------------------------------------------------------
. 2025-08-21 18:01:29.974 Session name: anonymous@localhost (Ad-Hoc site)
. 2025-08-21 18:01:29.974 Host name: localhost (Port: 21)
. 2025-08-21 18:01:29.974 User name: anonymous (Password: Yes, Key file: No, Passphrase: No)
. 2025-08-21 18:01:29.974 Transfer Protocol: FTP
. 2025-08-21 18:01:29.974 Ping type: Dummy, Ping interval: 30 sec; Timeout: 15 sec
. 2025-08-21 18:01:29.974 Disable Nagle: No
. 2025-08-21 18:01:29.974 Proxy: None
. 2025-08-21 18:01:29.974 Send buffer: 262144
. 2025-08-21 18:01:29.974 UTF: Auto
. 2025-08-21 18:01:29.974 FTPS: None [Client certificate: No]
. 2025-08-21 18:01:29.974 FTP: Passive: Yes [Force IP: Auto]; MLSD: Auto [List all: Auto]; HOST: Auto
. 2025-08-21 18:01:29.974 Local directory: default, Remote directory: home, Update: Yes, Cache: Yes
. 2025-08-21 18:01:29.975 Cache directory changes: Yes, Permanent: Yes
. 2025-08-21 18:01:29.975 Recycle bin: Delete to: No, Overwritten to: No, Bin path:
. 2025-08-21 18:01:29.975 Timezone offset: 0h 0m
. 2025-08-21 18:01:29.975 --------------------------------------------------------------------------
. 2025-08-21 18:01:30.413 Соединяюсь с localhost…
. 2025-08-21 18:01:32.049 Соединение с localhost установлено. Ожидаю приветствие…
< 2025-08-21 18:01:32.109 220 (vsFTPd 3.0.5)
> 2025-08-21 18:01:32.109 USER anonymous
< 2025-08-21 18:01:32.112 331 Please specify the password.
> 2025-08-21 18:01:32.112 PASS *********************
< 2025-08-21 18:01:32.117 230 Login successful.
> 2025-08-21 18:01:32.117 SYST
< 2025-08-21 18:01:32.119 215 UNIX Type: L8
> 2025-08-21 18:01:32.119 FEAT
< 2025-08-21 18:01:32.121 211-Features:
< 2025-08-21 18:01:32.121  EPRT
< 2025-08-21 18:01:32.121  EPSV
< 2025-08-21 18:01:32.121  MDTM
< 2025-08-21 18:01:32.121  PASV
< 2025-08-21 18:01:32.121  REST STREAM
< 2025-08-21 18:01:32.121  SIZE
< 2025-08-21 18:01:32.121  TVFS
< 2025-08-21 18:01:32.121  UTF8
< 2025-08-21 18:01:32.121 211 End
> 2025-08-21 18:01:32.121 OPTS UTF8 ON
< 2025-08-21 18:01:32.123 200 Always in UTF8 mode.
. 2025-08-21 18:01:32.174 Соединение установлено
. 2025-08-21 18:01:32.174 --------------------------------------------------------------------------
. 2025-08-21 18:01:32.174 Using FTP protocol.
. 2025-08-21 18:01:32.174 Doing startup conversation with host.
> 2025-08-21 18:01:32.190 PWD
< 2025-08-21 18:01:32.192 257 "/" is the current directory
. 2025-08-21 18:01:32.192 Getting current directory name.
. 2025-08-21 18:01:32.233 Получаю содержимое каталога…
> 2025-08-21 18:01:32.233 TYPE A
< 2025-08-21 18:01:32.235 200 Switching to ASCII mode.
> 2025-08-21 18:01:32.236 PASV
< 2025-08-21 18:01:32.238 227 Entering Passive Mode (192,168,0,111,148,18).
> 2025-08-21 18:01:32.238 LIST -a
. 2025-08-21 18:01:32.238 Соединяюсь с 192.168.0.111:37906…
. 2025-08-21 18:01:47.983 Превышено время ожидания (соединение потока передачи данных)
. 2025-08-21 18:01:47.986 Не могу получить содержимое каталога
. 2025-08-21 18:01:47.995 LIST with -a failed, will try pure LIST
. 2025-08-21 18:01:48.029 Соединяюсь с localhost…
. 2025-08-21 18:01:50.042 Соединение с localhost установлено. Ожидаю приветствие…
< 2025-08-21 18:01:50.088 220 (vsFTPd 3.0.5)
> 2025-08-21 18:01:50.088 USER anonymous
< 2025-08-21 18:01:50.091 331 Please specify the password.
> 2025-08-21 18:01:50.091 PASS *********************
< 2025-08-21 18:01:50.094 230 Login successful.
> 2025-08-21 18:01:50.094 SYST
< 2025-08-21 18:01:50.096 215 UNIX Type: L8
> 2025-08-21 18:01:50.096 FEAT
< 2025-08-21 18:01:50.098 211-Features:
< 2025-08-21 18:01:50.098  EPRT
< 2025-08-21 18:01:50.098  EPSV
< 2025-08-21 18:01:50.098  MDTM
< 2025-08-21 18:01:50.098  PASV
< 2025-08-21 18:01:50.098  REST STREAM
< 2025-08-21 18:01:50.099  SIZE
< 2025-08-21 18:01:50.099  TVFS
< 2025-08-21 18:01:50.099  UTF8
< 2025-08-21 18:01:50.099 211 End
> 2025-08-21 18:01:50.099 OPTS UTF8 ON
< 2025-08-21 18:01:50.100 200 Always in UTF8 mode.
. 2025-08-21 18:01:50.136 Соединение установлено
. 2025-08-21 18:01:50.136 Doing startup conversation with host.
> 2025-08-21 18:01:50.152 PWD
< 2025-08-21 18:01:50.154 257 "/" is the current directory
. 2025-08-21 18:01:50.154 Changing directory to "/".
> 2025-08-21 18:01:50.155 CWD /
< 2025-08-21 18:01:50.157 250 Directory successfully changed.
. 2025-08-21 18:01:50.157 Getting current directory name.
> 2025-08-21 18:01:50.158 PWD
< 2025-08-21 18:01:50.159 257 "/" is the current directory
. 2025-08-21 18:01:50.159 Startup conversation with host finished.
. 2025-08-21 18:01:50.187 Получаю содержимое каталога…
> 2025-08-21 18:01:50.187 TYPE A
< 2025-08-21 18:01:50.190 200 Switching to ASCII mode.
> 2025-08-21 18:01:50.190 PASV
< 2025-08-21 18:01:50.193 227 Entering Passive Mode (192,168,0,111,32,174).
> 2025-08-21 18:01:50.193 LIST
. 2025-08-21 18:01:50.193 Соединяюсь с 192.168.0.111:8366…
. 2025-08-21 18:02:05.983 Превышено время ожидания (соединение потока передачи данных)
. 2025-08-21 18:02:05.984 Не могу получить содержимое каталога
* 2025-08-21 18:02:06.067 (EFatal) **Соединение разорвано.**
* 2025-08-21 18:02:06.067 Превышено время ожидания (соединение потока передачи данных)
* 2025-08-21 18:02:06.067 Не могу получить содержимое каталога
* 2025-08-21 18:02:06.067 Не могу просмотреть каталог '/'.

Is there any way to fix this?
At the same time, access to another SSH server through an SSH tunnel works without problems.