The FTP connection using WinSCP.Session via SSH tunnel does not work.

Advertisement

kuzyaka
Joined:
Posts:
17

The FTP connection using WinSCP.Session via SSH tunnel does not work.

The FTP connection using WinSCP.Session via SSH tunnel does not work.
Using sshcPulkovo As SshClient = New SshClient(ciPulkovo)
  sshcPulkovo.Connect()
  If sshcPulkovo.IsConnected Then
    Dim intProxyPort As UInt16 = 5534
    Dim portDynamic As New ForwardedPortDynamic(intProxyPort)
    sshcPulkovo.AddForwardedPort(portDynamic)
    portDynamic.Start()
    If portDynamic.IsStarted Then
      For Each RowСклад As DataRow In dtСклад.Rows
        'ЗагрузитьФотоПоFTP(strФотоНасервере)
        Dim sessionOptions As New SessionOptions
        With sessionOptions
          .Protocol = Protocol.Ftp
          .HostName = "192.168.0.1"
          .UserName = "anonymous"
          .Password = ""
        End With
        'Next
        Using session As New Session
          ' Подключиться
          session.Open(sessionOptions)
          strФотоНасервере = "Фото/" & intIDPostavshik & "/" & RowСклад("Article") & ".jpg"
          imgFoto = GetImageFromFTP(strФотоНасервере)
          RowСклад("Image") = УменьшитьФото(intFrameHeight, intFrameWidth, imgFoto)
          imgFoto.Dispose()
        End Using
      Next
    End If
    portDynamic.Stop()
  End If
End Using

At the same time, connect to FTP using WinSCP.exe the SSH tunnel is working fine.
Using scPulkovo As New SshClient(ciPulkovo)
  Try
    scPulkovo.Connect()
    If scPulkovo.IsConnected Then
      If ПроверкаНаличияСервераTelnet(strHostName, 21) Then
        Dim intProxyPort As UInt16 = 5534
        Dim portDynamic As New ForwardedPortDynamic(intProxyPort)
        scPulkovo.AddForwardedPort(portDynamic)
        portDynamic.Start()
        If portDynamic.IsStarted Then
          If portDynamic.IsStarted Then
            Dim ProcessWinSCP As New Process
            ProcessWinSCP.StartInfo.FileName = "WinSCP.exe"
            ProcessWinSCP.StartInfo.Arguments = "data@" & strHostName & ""
            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
    End If
  Catch ex1 As Exception
    MessageBox.Show("Ошибка при создании туннеля!" & vbCrLf & ex1.Message,
                        "WinSCP",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Error)
  End Try

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
42,546
Location:
Prague, Czechia

Re: The FTP connection using WinSCP.Session via SSH tunnel does not work.

It's not clear from your code, where is the winscp.exe connecting. What is data@strHostName? It might be GUI-configured session that uses the intProxyPort.
In neither of your code you are actually using the forwarded port intProxyPort.
You have to use it to configure WinSCP to use proxy.
Please, post session log files from both codes, if you want us to check what exactly is happening.

Reply with quote

Advertisement

You can post new topics in this forum