3

I have used Winscp for file transferring and got details file transfer progress like below link,

File transfer details binding continuously until file transfered in window using WPF

and transfer code link below

https://winscp.net/eng/docs/library

But i need to cancel file transferring. Please give your suggestion.

Community
  • 1
  • 1
Arun D
  • 279
  • 3
  • 18

2 Answers2

2

To my understanding the only way to achieve this is to abort the current session.

link: https://winscp.net/eng/docs/library_session_abort

William Cross
  • 347
  • 1
  • 9
  • How to define Abort method? @William Cross – Arun D Apr 27 '17 at 04:25
  • if you follow the getfiles example here: https://winscp.net/eng/docs/library_session_getfiles - you will see that the getfiles method is invoked inside a new session (in this example, named session). If you were to abort the session that getfiles is contained within you would interrupt the file transfer. – William Cross Apr 27 '17 at 04:43
  • I have canceled file transferring with help of Abort();..Thanks @William Cross – Arun D Apr 27 '17 at 05:21
0

You can use FileTransferProgressEventArgs.Cancel:

bool cancel = false; // set to true to cancel the transfer

session.FileTransferProgress +=
    (sender, e) =>
    {
        if (cancel)
        {
            e.Cancel = true;
        }
    };

session.PutFiles(localPath, remotePath).Check();
Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992