【问题标题】:Cancel file transfers while transferring file to destination将文件传输到目的地时取消文件传输
【发布时间】:2020-09-16 16:01:32
【问题描述】:

我已经使用 Winscp 进行文件传输,并获得了如下链接的详细文件传输进度,

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

并在下方转码链接

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

但我需要取消文件传输。请给出你的建议。

【问题讨论】:

    标签: c# wpf winscp winscp-net


    【解决方案1】:

    据我了解,实现此目的的唯一方法是中止当前会话。

    链接:https://winscp.net/eng/docs/library_session_abort

    【讨论】:

    • 如何定义Abort方法? @威廉克罗斯
    • 如果您遵循此处的 getfiles 示例:winscp.net/eng/docs/library_session_getfiles - 您将看到 getfiles 方法在新会话中被调用(在此示例中,命名为会话)。如果您要中止包含 getfiles 的会话,则会中断文件传输。
    • 我在 Abort() 的帮助下取消了文件传输;..谢谢@William Cross
    【解决方案2】:

    你可以使用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();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-10
      • 2022-08-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-29
      相关资源
      最近更新 更多