如何在SFTP中返回系统类型?

时间:2017-10-10 15:28:10

标签: java ssh ftp sftp jsch

FTP和SFTP是不同的,但我想知道是否有等同于" SYST"用于SFTP的FTP命令。如果我使用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

2 个答案:

答案 0 :(得分:1)

部署最广泛的SFTP服务器是server中包含的OpenSSH。它实现了version 3 draft 2。 Jsch还实现了该版本的SFTP。

FTP SYST命令返回描述服务器系统类型的字符串。 Sftp版本3草案2没有实现像我可以看到的FTP SYST命令。没有命令可以返回服务器的操作系统或一组功能。

如果不知道为什么需要这些信息,就不可能说出如何解决这个问题。

答案 1 :(得分:1)

您可以使用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的支持。

相关问题