Connection Timed out

Advertisement

pmenage
Joined:
Posts:
3

Connection Timed out

I am trying to connect to a sftp site to upload a file but I cannot even open the connection because I receive the following error message:
Network error connection to "xxxxxxxxx" timed out(my site is different)

However It works when I use the WinSCP client.

My code is as below:
Dim sessionOptions As New SessionOptions

Try

' Setup session options
If TextProtocol.Text.ToString.Trim = "Protocol.Sftp" Then
sessionOptions.Protocol = 1
End If

sessionOptions.HostName = TextHostName.Text.ToString.Trim '"example.com"
sessionOptions.UserName = TextUserCode.Text.ToString.Trim '"user"
sessionOptions.Password = TextPassword.Text.ToString.Trim '"mypassword"
sessionOptions.SshHostKeyFingerprint = TextHostKeyFingerPrint.Text.ToString.Trim '"ssh-rsa 2048 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx"


Using session As New Session

' Connect
session.Open(sessionOptions)

' Upload files
Dim transferOptions As New TransferOptions
transferOptions.TransferMode = TransferMode.Binary

Dim transferResult As TransferOperationResult
'transferResult = session.PutFiles("d:\toupload\*", "/home/user/", False, transferOptions)
transferResult = session.PutFiles(TextLocalPath.Text.ToString.Trim, TextRemotePath.Text.ToString.Trim, False, transferOptions)

' Throw on any error
transferResult.Check()

' Print results
For Each transfer In transferResult.Transfers
MessageBox.Show("Upload of file " & transfer.FileName & " succeeded")
Next
End Using

I copied the source code proposed on the WinScp site.

I would be most grateful if could tell me why there is this time out and how to avoid it.

Regards

Patrick

Reply with quote

Advertisement

pmenage
Joined:
Posts:
3

Re: Connection Timed out

Please find attached the session log file. The source code is displayed below:

Private Sub BtnWinScpUpload_Click(sender As Object, e As System.EventArgs) Handles BtnWinScpUpload.Click

Dim sessionOptions As New SessionOptions
Dim tim As TimeSpan = TimeSpan.FromMinutes(1000)

Try

' Setup session options
sessionOptions.Protocol = Protocol.Sftp
sessionOptions.HostName = TextHostName.Text.ToString.Trim '"example.com"
sessionOptions.UserName = TextUserCode.Text.ToString.Trim '"user"
sessionOptions.Password = TextPassword.Text.ToString.Trim '"mypassword"
sessionOptions.SshHostKeyFingerprint = TextHostKeyFingerPrint.Text.ToString.Trim '"ssh-rsa 2048 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx"
sessionOptions.Timeout = tim

Using session As New WinSCP.Session
session.SessionLogPath = "C:\TestSftp\test\WinScp.log"


'if WinScp.exe is not in same path than WinScp.dll, then use the below line to point to WinScp.exe
'session.ExecutablePath = "C:\Download and Documentation\WinScp\winscp577automation\WinSCP.exe"

' Connect
session.Open(sessionOptions)

' Upload files
Dim transferOptions As New TransferOptions
transferOptions.TransferMode = TransferMode.Binary

Dim transferResult As TransferOperationResult
'transferResult = session.PutFiles("d:\toupload\*", "/home/user/", False, transferOptions)
transferResult = session.PutFiles(TextLocalPath.Text.ToString.Trim & TextFileName.Text.ToString.Trim, TextRemotePath.Text.ToString.Trim, False, transferOptions)

' Throw on any error
transferResult.Check()

' Print results
For Each transfer In transferResult.Transfers
MessageBox.Show("Upload of file " & transfer.FileName & " succeeded")
Next

End Using

Catch ex As Exception
MessageBox.Show("BtnWinScpUpload_Click : " & ex.Message & vbCrLf & "Source :" & ex.Source & "Stack Trace : " & ex.StackTrace)
End Try

End Sub
Description: Session Log File

Reply with quote

Advertisement

Advertisement

You can post new topics in this forum