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

asked 17 Feb '11, 05:08

Lance's gravatar image

Lance
181
accept rate: 0%


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.

link

answered 17 Feb '11, 22:31

Lukas%20Pokorny's gravatar image

Lukas Pokorny ♦♦
2.4k28
accept rate: 31%

I have to quit the late night coding sessions. Thanks, that was it.

(18 Feb '11, 00:28) Lance
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×144
×9
×4

Asked: 17 Feb '11, 05:08

Seen: 595 times

Last updated: 17 Feb '11, 22:31