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