Post a reply

Options
Add an Attachment

If you do not want to add an Attachment to your Post, please leave the Fields blank.

(maximum 10 MB; please compress large files; only common media, archive, text and programming file formats are allowed)

Options

Topic review

martin

Re: Error when copying file to sftp using vb.net

Checking (or posting here if you cannot help yourself) a session log (Session.SessionLogPath) file may provide more hints.
Also note that the exception likely has an inner exception associated, with more details.
JasonRkr

Aggyey,

I understand you can login to the server manually, but once in can you actually create a file? This sounds like a permissions issue.

Jason
Aggyey

Error when copying file to sftp using vb.net

Hi,
With the same login detail I can login to the server using WINSCP but getting error when doing it through vb.net
I am trying to copy the file to a sftp location but getting error the code I am using is:

*********************************************************************************
Try
' Setup session options
Dim sessionOptions As New SessionOptions
With sessionOptions
.Protocol = Protocol.Sftp
.HostName = remotehost
.UserName = username
.Password = password
.SshHostKeyFingerprint = "ssh-rsa 2048 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx"
End With
Using session As Session = New Session
' Connect
session.Open(sessionOptions)
' Upload files
Dim transferOptions As New TransferOptions
transferOptions.TransferMode = TransferMode.Automatic
Dim transferResult As TransferOperationResult
transferResult = session.PutFiles(filename, remotefolder, False, transferOptions)
' Throw on any error
transferResult.Check()
If transferResult.IsSuccess Then
errmsg = "Upload succeeded"
Return True
Else
' Print results
Dim transfer As TransferEventArgs
For Each transfer In transferResult.Transfers
errmsg = "ERROR file transfer - sending " & transfer.FileName
Next
End If
End Using
Catch e As Exception
errmsg = "ERROR session - " & e.Message
Return False
End Try
**************************************************************************************************

I am getting error at "transferResult.Check" the error is as follows:

"A first chance exception of type 'WinSCP.SessionRemoteException' occurred in WinSCP.dll
Cannot create remote file '/tCONF_MF_IN/con_mf_80063589_20130816100833.DAT'"

Please help!!!