[英]Remove or move only selected files with SFTP protocol using WinSCP .NET assembly
I'm trying to develop a simple SFTP file transferring project with following operations 我正在尝试使用以下操作开发一个简单的SFTP文件传输项目
While uploading in session.PutFiles()
we have a property called transferOptions.FileMask
to filter the files. 在
session.PutFiles()
上传时,我们有一个名为transferOptions.FileMask
的属性来过滤文件。
But I didn't see anything of that kind in session.MoveFile()
and in session.RemoveFiles()
但我在
session.MoveFile()
和session.RemoveFiles()
没有看到任何类似的东西。
My question is what should I do if I need to move/remove only selected files? 我的问题是,如果我需要移动/删除所选文件,我该怎么办?
The Session.RemoveFiles
accepts a file mask . Session.RemoveFiles
接受文件掩码 。
So you can do: 所以你可以这样做:
session.RemoveFiles("/home/user/*.txt");
It's the same as with the Session.PutFiles
. 它与
Session.PutFiles
相同。 The TransferOptions.FileMask
is actually intended for advanced selections, like when you want to select files recursively, or when you want to exclude certain types of files. TransferOptions.FileMask
实际上用于高级选择,例如,当您想要递归选择文件时,或者想要排除某些类型的文件时。
session.PutFiles(@"c:\toupload\*.txt", "/home/user/");
With the TransferOption.FileMask
, WinSCP would upload all matching files recursively. 使用
TransferOption.FileMask
,WinSCP将递归上传所有匹配的文件。 While with a simple file mask as the argument to the .PutFiles
, it's not recursive. 虽然使用简单的文件掩码作为
.PutFiles
的参数,但它不是递归的。
The Session.MoveFile
actually supports the file mask in its first argument too, though it's an undocumented feature. Session.MoveFile
实际上也支持第一个参数中的文件掩码, 尽管它是一个未记录的功能。
A proper way would be to list remote directory, select desired files and call the Session.MoveFile
for each. 一种正确的方法是列出远程目录,选择所需的文件并为每个文件调用
Session.MoveFile
。
See Listing files matching wildcard . 请参阅列出匹配通配符的文件 。 It's a PowerShell example, but mapping it to C# should be easy.
这是一个PowerShell示例,但将其映射到C#应该很容易。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.