login about faq

My function below is working exactly as per the requirement.
I wrote a Sftp program which creates a csv file from byte variable.

Issue is the file folder path. Folder path has to be picked from URI variable. At present, folder path goes based on the username you log into the ftp file path.

Public Function UploadFileFromStream(ByVal _data As Byte(), ByVal _fileName As String) As Boolean


            Dim sftp As New Chilkat.SFtp()

            Dim success As Boolean
            success = sftp.UnlockComponent("Anything for 30-day trial")

            sftp.ConnectTimeoutMs = 5000
            sftp.IdleTimeoutMs = 10000

            success = sftp.Connect(_uri, _port)

            If (success <> True) Then
                Exit Function
            End If

            '  Authenticate with the SSH server. Either Password or Public Key Authentication

            success = sftp.AuthenticatePw(_userId, _password)
            If (success <> True) Then
                Exit Function
            End If

            '  After authenticating, the SFTP subsystem must be initialized:
            success = sftp.InitializeSftp()
            If (success <> True) Then
                Exit Function
            End If

            Dim handle As String
            handle = sftp.OpenFile(_fileName, "writeOnly", "createTruncate")
            If (handle = vbNullString) Then
                Exit Function
            End If

            success = sftp.WriteFileBytes(handle, _data)
            If (success <> True) Then
                Exit Function
            End If

        Catch ex As Exception
            Throw New Exception(ex.Message)
        End Try

        Return True

    End Function

    _userid    : USER_NAME_123
    _password  : PWD123
    _uri       : ftp://comp_hostname:21/home/admin/folder-a/data/sub-folder-a/

Expected :-


Present Output :- It goes to the Default folder. Which is under the username you log in.


asked Sep 11 '14 at 12:50

chilldll's gravatar image


edited Sep 11 '14 at 13:33


I have run in to this before, ftp and sftp treat folders differently. My suggestion would be to login to your server via sftp with a client like filezilla or cuteftp so you can see the path that you need to use.



answered Sep 11 '14 at 13:01

emartinson's gravatar image


Thank you for this tip !! Let me verify the details and get back to you. Let the question be open for now.

(Sep 11 '14 at 13:32) chilldll

http://www.example-code.com/vbnet/sftp_changeDirectory.asp - On reading this link. I can understand that File folder will work different for sftp. But i have to Copy or Cut the file from Root directory to the mentioned folder path. Do sftp support Copy. I do know that they have sftp.RemoveFile property

(Sep 11 '14 at 15:36) chilldll

@emartinson, Have you used any CopyFile Property / Method to copy the file from Root Directory to the mentioned folder path ? I have to move the file from Root Directory to the mentioned folder path which is crucial part of the req

(Sep 11 '14 at 16:02) chilldll

I have not copied a file before on sftp but I have in ftp. The way that I was able to copy was to download the file and then upload it in the new location.

(Sep 11 '14 at 16:57) emartinson

@emartinson, you mentioned in the answer about filezilla or cuteftp. We are using securefx which is similar to these. I wasn't allowed to install these softwares at my work computer. When i checked with network admin, he insiste me to use securefx. I can see the file path and files in it.

(Sep 12 '14 at 12:05) chilldll
Your answer
toggle preview

Follow this question

By Email:

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



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



Asked: Sep 11 '14 at 12:50

Seen: 2,166 times

Last updated: Sep 12 '14 at 12:05

powered by OSQA