I have the following code which starts a download:

_transferClient = new Ftp { Timeout = -1 };
_transferClient.Options |= FtpOptions.KeepAliveDuringTransfer;
_transferClient.Connect(SessionSettings.Server);
_transferClient.Login(SessionSettings.Username, SessionSettings.Password);
_transferClient.GetFile(RemotePath, LocalPath);

Then, in a button event handler, I have this code which attempts to cancel the upload, disconnect, then dispose the Ftp object

_transferClient.Abort();
_transferClient.Disconnect();
_transferClient.Dispose();
_transferClient = null;

What is the correct way to do this without receiving the "Another operation is pending" exception?

asked 20 Apr '11, 20:51

John%20Hancock's gravatar image

John Hancock
251
accept rate: 0%

edited 22 Apr '11, 02:24

Martin%20Vobr's gravatar image

Martin Vobr ♦♦
335310


If you simply need to abort the transfer and disconnect, just call the Dispose method (without calling Abort or Disconnect first). This will immediately close both the data connection and control connection and won't throw "Another operation is pending" exception.

The Abort method is only useful if you need to abort the transfer but keep the connection active. It doesn't abort the transfer immediately, but within several seconds. This means you would have to wait for the actual operation to fail before calling another method (including Disconnect).

link

answered 20 Apr '11, 23:18

Lukas%20Pokorny's gravatar image

Lukas Pokorny ♦♦
2.4k28
accept rate: 31%

thanks a lot. that seems to work fine

(21 Apr '11, 23:20) John Hancock
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:

×152
×22
×20
×3
×3

Asked: 20 Apr '11, 20:51

Seen: 459 times

Last updated: 22 Apr '11, 02:24