Topic "VB/Com Method timeout with upload"

Author Message
michaelvlong
[View user's profile]

Joined: 2013-12-27
Posts: 1
Location: California USA
Firstly... thank you up front for any help you may be able to provide!

WinSCP.exe verion = 5.5.0.3839
Language = VB6/Com

Issue:
I am not able to sucessfully connect and upload a file to a remote SFTP server using VB/Com.
Remote connection requirement has specific port number (10022), but trying to apply the port into the VB/com parameters has not sucessfully worked thus far.

Desired resolution:
Ability to compose vb/com parms to sucessfully connect to sftp server with a specific port

Context:
When I manually connect via WinSCP.exe I can connect to the remote server - no issues
Parms used:
File Protocol = SFTP
Host name = <ipaddress>
Port number = 10022
User name = <username>
Password = <password>
sshHostKey = <hostkey saved in ini>

Using VB/Com:
1. Adding ":port" to host name - Get response - Error: Host "ipaddress:10022" does not exist. This response is practially immediate.

2. Do not add ":port" to hostname - Get response - Error: Network Error: Connection to "ipaddress" timed out. This takes several seconds to return back with the response.

3. Adding any prefix to the ipaddress ie "ftp://ipaddress" also fails (probably as expected) with error that host does not exist

Source code:

Private Sub Command4_Click()

Dim mySession As New Session

' Enable custom error handling
On Error Resume Next

SCPUpload mySession

' Query for errors
If Err.Number <> 0 Then
MsgBox "Error: " & Err.Description

' Clear the error
Err.Clear
End If

' Disconnect, clean up
mySession.Dispose

End Sub

Private Sub SCPUpload(ByRef mySession As Session)

' Setup session options
Dim mySessionOptions As New SessionOptions

Dim wUrl As String
wUrl = Me.txtUrl.Text
If Me.txtPort.Text <> "" Then
wUrl = wUrl & ":" & Me.txtPort.Text
End If

With mySessionOptions
.Protocol = Protocol_Sftp
.HostName = wUrl
.UserName = Me.txtUsername.Text
.Password = Me.txtPassword.Text
.SshHostKeyFingerprint = Me.txtHostKey.Text
End With

' Connect
mySession.Open mySessionOptions

' Upload files
Dim myTransferOptions As New TransferOptions
myTransferOptions.TransferMode = TransferMode_Binary

Dim transferResult As TransferOperationResult
Set transferResult = mySession.PutFiles(Me.txtSource.Text, "", False, myTransferOptions)

' Throw on any error
transferResult.Check

' Display results
Dim transfer As TransferEventArgs
For Each transfer In transferResult.Transfers
MsgBox "Upload of " & transfer.FileName & " succeeded"
Next

End Sub
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24512
Location: Prague, Czechia
Just use SessionOptions.PortNumber property:
http://winscp.net/eng/docs/library_sessionoptions#properties
_________________
Martin Prikryl
Advertisements

You can post new topics in this forum






Search Site

What is WinSCP?

It is award-winning SFTP client, SCP client, FTPS client and FTP client integrated into one software program for file transfer to FTP server or secure SFTP server. [More]

And it's free!

Donate

About donations

$9   $19   $49   $99

About donations

Recommend

WinSCP Privacy Policy

WinSCP License