在 sshj v0.5.0 中上传和下载文件时设置文件过滤器
我一直在使用 sshj 库,
<dependency>
<groupId>net.schmizz</groupId>
<artifactId>sshj</artifactId>
<version>0.3.1</version>
</dependency>
以下是我使用 0.3.1 的代码,它可以很好地上传支持通配符模式的文件。
SSHClient client = null;
SCPUploadClient uploader = null;
try {
client = getClient();
uploader = client.newSCPFileTransfer().newSCPUploadClient();
uploader.setFileFilter(new WildcardFileFilter(wildCardPattern));
//determine the remote directory
File f = new File(localDirLocation);
String dir = remoteDirLocation + f.getName();
uploader.copy(localDirLocation, remoteDirLocation);
} catch (IOException e) {
//processing exceptions here
} finally {
disconnectClient(client);
}
但现在,当我尝试转向 0.5.0 时,代码出现了很多编译错误。
我想了解当我想要从本地计算机上传和下载文件到远程计算机时如何设置文件过滤器,反之亦然
有人可以帮助我吗?
I have been using sshj libraries
<dependency>
<groupId>net.schmizz</groupId>
<artifactId>sshj</artifactId>
<version>0.3.1</version>
</dependency>
Following was my code using 0.3.1 which worked fine for doing uploading of files supporting wildcard patterns.
SSHClient client = null;
SCPUploadClient uploader = null;
try {
client = getClient();
uploader = client.newSCPFileTransfer().newSCPUploadClient();
uploader.setFileFilter(new WildcardFileFilter(wildCardPattern));
//determine the remote directory
File f = new File(localDirLocation);
String dir = remoteDirLocation + f.getName();
uploader.copy(localDirLocation, remoteDirLocation);
} catch (IOException e) {
//processing exceptions here
} finally {
disconnectClient(client);
}
But now the code gives me a lot of compilation errors when I tried moving over to 0.5.0.
I would like to understand how do I go about setting fileFilters when I want to do uploading and downloading of files from local to remote machine and vice versa
Can someone please help me with this ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
目前使用 0.5.0,这不再可能。我为 SSHJ 的 Shikhar(维护者)创建了一个拉取请求。
下面我修改了您的代码示例以使其与 0.5.0 一起工作。基本的变化是您现在需要向复制方法提供 LocalSourceFile。为了使 SCPUploadClient 能够仅发送目录的过滤内容,我重写了 getChildren(LocalFileFilter) 方法。
对于 WildcardFileFilter 请参阅我关于如何在 0.6.0 中执行此操作的第二个答案。
希望这有帮助。
Currently using 0.5.0 this is no longer possible. I created a pull request for Shikhar (the maintainer) of SSHJ.
Below I've adapted your code sample to make it work with 0.5.0. The basic change is that you now need to provide a LocalSourceFile to the copy method. In order to make it possible for the SCPUploadClient to only send the filtered contents of the directory, I've overridden the getChildren(LocalFileFilter) method.
For the WildcardFileFilter see my second answer on how to do this in 0.6.0.
Hope this helps.
使用 0.6.0,您可以编写代码如下:
我猜您使用的 WildcardFileFilter 来自 commons-io。由于这是一个 FilenameFilter 而不是 LocalFileFilter,因此您可以非常简单地将其实现为:
Using 0.6.0 you can write your code as follows:
The WildcardFileFilter you used came from commons-io I guess. As that is a FilenameFilter and not a LocalFileFilter, you could very simply implement this as: