Hi!
This software is awesome! :)
I have a command line application in VB.NET that transfers a bunch of data files to a remote server once every hour (see code below).
My problem is if an error occurs during the Session.PutFiles function, the upload stops and all the remaining files aren't transfered to the server.
The error I got is:
scp: /apps/local/bdq/data/reception/chqc_02MC005_20130620_0815_ecshe.dat: set times: No such file or directory
How can I catch the error but resume the upload for the remaining files?
I'll leave for a long week-end soon but I'll check any reply when I'll get back Thuesday.
Thanks a lot!
Main part of code:
Public Sub TransfertSCP(scpAtt As scpAccess, xfertpath As String)
Dim sessOpt As New SessionOptions
With sessOpt
.Protocol = Protocol.Scp
.HostName = scpAtt.HostName
.UserName = scpAtt.UserName
.SshHostKeyFingerprint = scpAtt.SshHostKeyFingerprint
.SshPrivateKeyPath = scpAtt.SshPrivateKeyPath
End With
Using Session As Session = New Session
Try
Session.ExecutablePath = System.AppDomain.CurrentDomain.BaseDirectory() & "ssh\WinSCPnet.exe"
' Connect
Session.Open(sessOpt)
' Upload files
Dim transferOptions As New TransferOptions
transferOptions.TransferMode = TransferMode.Ascii
writeLog(app.path_log, app.filename_log, _
String.Format("Files in {0} to transfer: {1}", xfertpath, Directory.GetFiles(xfertpath).Count), LogLevel.INF)
Dim transferResult As TransferOperationResult
transferResult = Session.PutFiles(xfertpath, scpAtt.RemoteFolder, False, transferOptions)
writeLog(app.path_log, app.filename_log, _
String.Format("Files in {0} transfered: {1}", xfertpath, transferResult.Transfers.Count), LogLevel.INF)
For Each err As SessionRemoteException In transferResult.Failures
writeLog(app.path_log, app.filename_log, String.Format("ERROR SCP Transfer failed: {0}", err.Message))
Next
' Print transfert
For Each transfer As TransferEventArgs In transferResult.Transfers
Console.WriteLine("Upload of {0} succeeded", transfer.FileName)
writeLog(app.path_log, app.filename_log, String.Format("SCP Transfer successful: {0}", transfer.FileName))
Next
Catch ex As Exception
writeLog(app.path_log, app.filename_log, String.Format("ERROR SCP Transfet {0}", ex.Message))
End Try
End Using
End Sub