使用hadoop文件系统api访问sftp

时间:2019-04-26 12:41:31

标签: java hadoop filesystems sftp

使用hadoop文件系统访问sftp无法停止应用程序 代码在下面给出

public static void main(String[] args) {
    String sftpDir = "sftp://username:password@ftp-host/home/username/ftp/files/test";
    Configuration configuration = new Configuration();
    configuration.set("fs.sftp.impl", org.apache.hadoop.fs.sftp.SFTPFileSystem.class.getName());
    Path path = new Path(sftpDir);
    FileSystem fs;
    try {
        fs = path.getFileSystem(configuration);
        boolean exists = fs.exists(path);
        System.out.println("sftp exists: " + exists);
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

用实际的用户名/密码替换用户名/密码。 在eclipse中执行此代码后,即使程序到达末尾,应用程序也不会停止。

还尝试使用fs.close();但没有用。 任何解决此问题的建议将不胜感激。

注意:如果使用ftp代替sftp,例如:“ ftp://username:password@ftp-host/files/test”,则程序将停止执行而不会出现任何问题。

预先感谢

0 个答案:

没有答案