【问题标题】:Do not traverse directories using the WinSCP .NET assembly不要使用 WinSCP .NET 程序集遍历目录
【发布时间】:2014-01-02 18:58:41
【问题描述】:

我正在尝试使用WinSCP .NET 程序集将文件夹的内容(但不是包含备份文件、存档文件和错误文件的子文件夹)的内容上传到服务器。这甚至可能吗?如果是这样,我该怎么做?

我现有作品的快速代码剪辑:

// string mode ...
// Session sess ...
// TransferOperationResult res ...

TransferOptions tOpts = new TransferOptions();
tOpts.FileMask = c.SearchPattern;
tOpts.TransferMode = TransferMode.Binary;
tOpts.PreserveTimestamp = true;

SetMessage("Uploading files");
res = sess.PutFiles(Path.Combine(c.LocalPath, c.SearchPattern),
                    c.RemotePath, 
                    c.DeleteAfterXFer, 
                    tOpts);

有没有什么方法可以说:

tOpts.TopDirectoryOnly = true

?

【问题讨论】:

    标签: winscp winscp-net


    【解决方案1】:

    使用file mask |*/ to exclude all (sub-)directories

    使用TransferOptions.FileMask property 设置文件掩码。

    TransferOptions transferOptions = new TransferOptions();
    transferOptions.FileMask = "|*/";
    
    session.PutFiles(@"d:\toupload\*", "/home/user/", false, transferOptions).Check();
    

    针对您的样品,请执行以下操作:

    tOpts.FileMask = c.SearchPattern + "|*/";
    

    也记录在 WinSCP FAQ How do I transfer (or synchronize) directory non-recursively?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-12-13
      • 2014-07-12
      • 1970-01-01
      • 2015-03-17
      • 1970-01-01
      • 1970-01-01
      • 2015-08-07
      • 2013-01-23
      相关资源
      最近更新 更多