login about faq

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.

Module TestConnection

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

End Sub

End Module

asked Nov 20 '15 at 15:58

Barry's gravatar image

Barry
1


Why is this a problem? The handle is "00000000". It should be a valid handle when passed to DownloadFile and CloseHandle...

link

answered Nov 20 '15 at 16:14

chilkat's gravatar image

chilkat ♦♦
11.8k316358421

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

link

answered Nov 23 '15 at 08:22

Barry's gravatar image

Barry
1

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or __italic__
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×5

Asked: Nov 20 '15 at 15:58

Seen: 441 times

Last updated: Nov 23 '15 at 08:22

powered by OSQA