简体   繁体   English

WinSCP .NET程序集:目录同步中的FileMask不起作用

[英]WinSCP .NET assembly: FileMask in Directory Synchronization not working

Here is what I want to do in laymen terms first: I want to get files (and maybe some files only). 这是我想首先用外行的话做的:我想获取文件(也许只有一些文件)。 If there are sub-directories, I want to get files in those sub-directories as well. 如果有子目录,我也想在这些子目录中获取文件。 I am using Visual C++/CLI to program, so I am using .net assembly. 我正在使用Visual C ++ / CLI进行编程,所以我正在使用.net程序集。

In WinSCP, that is to use Session.SynchronizeDirectories() . 在WinSCP中,即使用Session.SynchronizeDirectories() The last parameter is the TransferOptions (a class) and it is usually set to null. 最后一个参数是TransferOptions (一个类),通常将其设置为null。 Basically that means every files will be transferred. 基本上,这意味着每个文件都会被传输。 If I create an object and set the property string FileMask , I should be able to transfer only certain files. 如果创建对象并设置属性string FileMask ,那么我应该只能传输某些文件。

So I change the WinSCP C# example program to: 因此,我将WinSCP C#示例程序更改为:

using (Session session = new Session())
{
    // Will continuously report progress of synchronization
    session.FileTransferred += FileTransferred;

    // Connect
    session.Open(sessionOptions);

    // Create a TransferOptions object
    TransferOptions tro = new TransferOptions();
    tro.FileMask = "*.txt";
    tro.TransferMode = TransferMode.Automatic;

    // Synchronize files
    SynchronizationResult synchronizationResult;
    synchronizationResult =
        session.SynchronizeDirectories(
             SynchronizationMode.Local, @"C:\temp\win", "/C/Users/peter/Documents/WinSCP5.5.1/",
             false, false, SynchronizationCriteria.Time, tro);

    // Throw on any error
    synchronizationResult.Check();
}

When I run the program, everything in the current directory and sub-directories are transferred! 当我运行该程序时,当前目录和子目录中的所有内容都会被传输!

Thinking I may be wrong in the specifying those options. 认为我在指定这些选项时可能是错误的。 I use the WinSCP program. 我使用WinSCP程序。 (Can refer to picture in WinSCP web site Transfer Settings Dialog page.) (可以参考WinSCP网站“ 传输设置”对话框页面中的图片。)

All options are clear except I enter the following for the File mask: *.txt 除我为文件掩码输入以下内容外,所有选项均清除: *.txt

I click OK button to begin transfer. 我单击“确定”按钮开始传输。 I have the preview option on. 我启用了预览选项。 And I see only txt files selected, even the one in the sub-directories . 而且我只看到选择的txt文件,甚至在子目录中也是如此

So WinSCP program works, but not the API? 因此WinSCP程序可以工作,但API不行吗?

[Edit] I am using version 5.5.2 of WinSCP assembly. [编辑]我正在使用WinSCP程序集的5.5.2版。

Finally I get it working before Easter holiday. 最后,我让它在复活节假期之前开始工作。 After working with @Martin for sometime, I pass through the problem. 与@Martin合作一段时间后,我解决了这个问题。 (Note that I am not saying I have found out the solution.) :( (请注意,我并不是说我已找到解决方案。)

Anyway, I download the source code for WinSCP 5.5.2 version. 无论如何,我下载了WinSCP 5.5.2版本的源代码。 I have to modify the project from dot net version 4 back to version 3.5 as I am using Visual Studio 2008. I include it in my original project. 当我使用Visual Studio 2008时,我必须将项目从点号网络版本4修改回版本3.5。我将其包含在原始项目中。 Compile it. 编译它。 OK. 好。 I have the original project to use that output DLL. 我有原始项目使用该输出DLL。 I make sure the WinSCP EXE is also verison 5.5.2. 我确保WinSCP EXE的版本也为5.5.2。 Run it. 运行。 No problem. 没问题。 File mask is working. 文件掩码正在工作。

Just a side story if you are interested. 如果您感兴趣的话,只是个小故事。 After using the source code project, I remove it. 使用源代码项目后,我将其删除。 I use back the 5.5.2 DLL downloaded from website. 我使用了从网站下载的5.5.2 DLL。 Suddenly the program needs 30s or so to execute the first statement. 突然,程序需要30秒钟左右的时间来执行第一条语句。 I then use version 5.5.1 EXE and DLL. 然后,我使用5.5.1版EXE和DLL。 Same delay. 同样的延迟。 Switch to 5.5.3 EXE and DLL. 切换到5.5.3 EXE和DLL。 Same 30s or so delay. 相同的30秒左右的延迟。 Remove the DLL and use 5.5.3 .net assembly source code. 删除DLL,并使用5.5.3 .net程序集源代码。 Compile it. 编译它。 Program runs immediately. 程序立即运行。

I guess from now on I will compile my .net assembly and use it. 我想从现在开始,我将编译.net程序集并使用它。

Thanks Martin for help. 谢谢马丁的帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM