Error on SFTP.BeginPutFile when AsyncCallback Method is Called

0 votes
asked Feb 17, 2011 by Lance (270 points)
edited Feb 17, 2011

I am getting the following error when the AsyncCallback Method is called after the method SFtp.BeginPutFile has finished uploading the file. I would like to call a fixed number of threaded uploads and have the AsyncCallback method called when each one has completed.

The IAsyncResult object returned from the UploadComplete method does show the _result variable with the size of the file that was successfully uploaded when I inspect the variable n Visual Studio.

System.ArgumentException was caught Message=The IAsyncResult object supplied to GetFileInternal was not returned from the corresponding GetFileInternal method on this class. Parameter name: asyncResult ParamName=asyncResult Source=Rebex.Net.Sftp StackTrace: at Rebex.Net.Sftp.EndAsync(IAsyncResult asyncResult, MethodBase method) in c:\Data\Build\WorkingDirectory\Rebex.AllPackages\output\Sftp\dist\input\sc\Sftp\Sftp.cs:line 377 at Rebex.Net.Sftp.EndGetFile(IAsyncResult asyncResult) in c:\Data\Build\WorkingDirectory\Rebex.AllPackages\output\Sftp\dist\input\sc\Sftp\Sftp.cs:line 2996 at SFTP_Backup.frmMain.UploadComplete(IAsyncResult asyncResult) in C:\Projects2010\SFTP Backup\SFTP Backup\WinForms\frmMain.vb:line 660 InnerException:

Private Sub cmdStartThreading_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdStartThreading.Click

    ConnectToSFTPServer()

    ' Begin Asynchronous Transfer 
    Dim asyncResult As IAsyncResult

    asyncResult = ftp.BeginPutFile("C:\Reports\File1.txt", "/File1.txt", New AsyncCallback(AddressOf UploadComplete), Nothing)

End Sub


Private Sub UploadComplete(ByVal asyncResult As IAsyncResult)
   Try
      ' get the result 
      Dim bytes As Long

      ' Error occurs on the next line
      bytes = ftp.EndGetFile(asyncResult)


      Catch ex As Exception
         Log.Error(ex, System.Reflection.MethodInfo.GetCurrentMethod.Name, "Error", ex.ToString, "")

      End Try
   End Sub
Applies to: Rebex SFTP

1 Answer

0 votes
answered Feb 17, 2011 by Lukas Pokorny (100,710 points)
edited Feb 17, 2011
 
Best answer

It looks like you call EndGetFile on an asyncResult object returned by BeginPutFile:

Operation begins:

asyncResult = ftp.BeginPutFile("C:\Reports\File1.txt", "/File1.txt", New AsyncCallback(AddressOf UploadComplete), Nothing)

Operation ends:

' Error occurs on the next line
bytes = ftp.EndGetFile(asyncResult)

Changing the EndGetFile call to EndPutFile should solve the problem.

commented Feb 17, 2011 by Lance (270 points)
I have to quit the late night coding sessions. Thanks, that was it.
...