FTP 和 SFTP 是不同的,但我想知道 SFTP 中是否有相当于 FTP 中“SYST”命令的命令。如果我有一个使用 JSch 的 SFTP 连接并且我想返回系统类型,我该怎么做?我正在将 FTP 连接转换为 SFTP。如果无法使用 SFTP,是否有解决方法?
public String getSystemType()
throws IOException, FtpException
{
if(out == null)
return null;
acquire(); // Acquire the object
try {
ftpCommand("SYST"); //sends command to FTP to retrieve the system type.
if(!reply.substring(0, 3).equals("215"))
throw new FtpException(reply);
} finally {
release(); // Release the object
}
return reply.substring(4);
}
我需要这个“系统类型”来解析某个位置的文件或目录信息的结果。它可以是 Windows 服务器或 UNIX 服务器。根据我需要解析它来检索
1) 姓名
* 2) 权限..在MSDOS格式列表中不可用
* 3) 类型
* 4) 所有者..在 MSDOS 格式列表中不可用
* 5) 组..在 MSDOS 格式列表中不可用
* 6) 尺寸
* Parse a UNIX format list. With skipping number of lines.
* The columns of a typical UNIX format list is like:
* drwxr-xr-x 6 appli appli 1024 May 17 20:33 java
* -rw------- 1 appli appli 1005 May 1 21:21 mp3list
* drwxr-xr-x 5 appli appli 1024 May 17 16:56 perl
* drwxr-xr-x 6 appli appli 1024 Apr 30 23:18 public_html
// Some UNIX format list doesn't contain the column for group like this:
// -rw-r--r-- 1 daemon 0 Dec 7 10:15 .notar
// -r--r--r-- 1 daemon 828 Mar 30 1995 HOW_TO_SUBMIT
// -r--r--r-- 1 daemon 627 Mar 30 1995 README
// -r--r--r-- 1 daemon 876 Mar 30 1995 WELCOME
// drwxr-xr-x 2 ftp 512 Oct 13 1999 bin
最佳答案
您可以使用 SSH 版本字符串。
就像:
- SSH-2.0-OpenSSH_5.3
- SSH-2.0-7.34 FlowSsh:Bitvise SSH 服务器 (WinSSHD) 7.34
- SSH-2.0-1.36_sshlib GlobalSCAPE
- SSH-2.0-mod_sftp/0.9.8
在 JSch 中,您可以使用 Session.getServerVersion
检索它.
SFTP 本身仅使用 optional extension "vendor-id" 提供有关远程系统的信息。 ,很少受到支持。 JSch 本身绝对不支持它,最广泛的 SFTP 服务器实现 OpenSSH 也不支持它。
<小时/>但请注意,使用 SFTP,您通常不需要解析目录列表。在 SFTP 中,大多数列表数据都以二进制结构的形式出现,而不是像 FTP 那样的文本列表。
关于java - 如何在 SFTP 中返回系统类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46670532/