Error during Session.PutFiles. Files remaining not uploaded.

Advertisement

Akarius
Joined:
Posts:
9
Location:
Canada

Error during Session.PutFiles. Files remaining not uploaded.

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

Reply with quote

Advertisement

Akarius
Joined:
Posts:
9
Location:
Canada

I've added this line in the code and it solved the set times: No such file or directory error.
transferOptions.PreserveTimestamp = False
...but I still want it to continue the remaining uploads if an error occurs and I don't know how I can do this.

I could upload the file one by one but since I have to proceed about 400 files each hour, it'd be too time-consuming.

Any help welcome!

Reply with quote

gholmes
Joined:
Posts:
7
Location:
United States

I wonder if you could use separate threads? Or would the WinSCP instances step on each other?

(Just reaching ... apologies if the idea is ludicrous for some reason ) :lol:

Reply with quote

Akarius
Joined:
Posts:
9
Location:
Canada

I could give it a try...in a future version...when I'll have the time :?

For the moment, it works great.
If it ain't broke, don't fix it!
:D

Thanks for the insight.

Reply with quote

Advertisement

Advertisement

You can post new topics in this forum