Question:
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
Try
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
MsgBox(sftp.LastErrorText)
Exit Function
End If
' Authenticate with the SSH server. Either Password or Public Key Authentication
success = sftp.AuthenticatePw(_userId, _password)
If (success <> True) Then
MsgBox(sftp.LastErrorText)
Exit Function
End If
' After authenticating, the SFTP subsystem must be initialized:
success = sftp.InitializeSftp()
If (success <> True) Then
MsgBox(sftp.LastErrorText)
Exit Function
End If
Dim handle As String
handle = sftp.OpenFile(_fileName, "writeOnly", "createTruncate")
If (handle = vbNullString) Then
MsgBox(sftp.LastErrorText)
Exit Function
End If
success = sftp.WriteFileBytes(handle, _data)
If (success <> True) Then
MsgBox(sftp.LastErrorText)
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 :-
HOME
ADMIN
FOLDER-A
DATA
SUB-FOLDER-A
Present Output :- It goes to the Default folder. Which is under the username you log in.
HOME
USER_NAME_123
chilldll,
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.
-Erik