【发布时间】:2017-02-05 12:45:11
【问题描述】:
我是 SFTP 协议的新手。我需要使用 SFTP 协议列出来自服务器的所有文件和文件夹。我使用 JSch 库实现了这个:
public ArrayList<JSONObject> listFiles(String deviceName, String location) throws Exception
{
this.sftpLogin();
Vector fileListVector;
if (Strings.isNullOrEmpty(location))
{
fileListVector = channelSftp.ls("/");
} else
{
fileListVector = channelSftp.ls("/"+location);
}
ArrayList<JSONObject> fileList = new ArrayList<>();
for (Object aFileListVector : fileListVector)
{
ChannelSftp.LsEntry entry = (ChannelSftp.LsEntry) aFileListVector;
if (entry.getFilename().equalsIgnoreCase(".") || entry.getFilename().equalsIgnoreCase(".."))
{
continue;
}
SftpATTRS attrs = entry.getAttrs();
fileList.add(ImportProtocolUtils.getFileJSONObject(attrs.isDir(), location, entry.getFilename()));
}
return fileList;
}
我使用这个协议尝试了“shell”和“exec”通道。但是命令 'ls' 不起作用。
在 Java 中哪个是最好的库?
提前致谢。
【问题讨论】: