When I try to open the file with an incorrect path or file name I get the error "No such file"
When I try to open the file with the correct path and file name the handle has a value of "00000000".
Any insight on this issue would be greatly appreciated. Here is the code.
Sub Main() ' Important: It is helpful to send the contents of the ' sftp.LastErrorText property when requesting support. Dim sftp As New Chilkat.SFtp() ' Any string automatically begins a fully-functional 30-day trial. Dim success As Boolean = sftp.UnlockComponent("Anything for 30-day trial") If (success <> True) Then MsgBox(sftp.LastErrorText) Exit Sub ' Else ' MsgBox("Component Unlocked") End If ' Set some timeouts, in milliseconds: sftp.ConnectTimeoutMs = 15000 sftp.IdleTimeoutMs = 15000 ' To use a SOCKS4 or SOCKS5 proxy, simply set the following ' properties prior to connecting: ' The SOCKS hostname may be a domain name or ' IP address: sftp.SocksHostname = "socksHostName" sftp.SocksPort = 1080 ' Set the SOCKS version to 4 or 5 based on the version ' of the SOCKS proxy server: sftp.SocksVersion = 5 Dim port As Integer Dim hostname As String hostname = "externalHostName" port = 22 success = sftp.Connect(hostname, port) If (success <> True) Then MsgBox(sftp.LastErrorText) Exit Sub Else MsgBox("Connection OK") End If ' Authenticate with the SSH server. Chilkat SFTP supports ' both password-based authenication as well as public-key ' authentication. This example uses password authenication. success = sftp.AuthenticatePw("userName", "userPassword") If (success <> True) Then MsgBox(sftp.LastErrorText) Exit Sub Else MsgBox("Login OK") End If ' After authenticating, the SFTP subsystem must be initialized: success = sftp.InitializeSftp() If (success <> True) Then MsgBox(sftp.LastErrorText) Exit Sub Else MsgBox("Initialization OK") End If ' Open a file on the server: Dim handle As String handle = sftp.OpenFile("subDirectory/fileName.DAT", "readOnly", "openExisting") If (handle = vbNullString) Then MsgBox(sftp.LastErrorText) Exit Sub Else MsgBox("File openned") End If
' Download the file: success = sftp.DownloadFile(handle, "localPath/") If (success <> True) Then MsgBox(sftp.LastErrorText) GoTo CloseFexCoData Else MsgBox("File downloaded") End If
' Close the file.
CloseFexCoData: success = sftp.CloseHandle(handle) If (success <> True) Then MsgBox(sftp.LastErrorText) Exit Sub Else MsgBox("Disconnect OK") End If
Why is this a problem? The handle is "00000000". It should be a valid handle when passed to DownloadFile and CloseHandle...
Thank you for the quick response.
I am new to this. Your reply made me look closer at the destination for the download and there was an incomplete path. I thought the file name opened would land in the destination with specifying the actual name.
For testing I used the actual file name. When in production I will need to use a wild card to get the file. Can I use the wild card in the destination file name or is there a way to capture the full name of the file opened?
Thank you, Barry