How to retrieve a file from a server via SFTP?

后端 未结 16 1521
萌比男神i
萌比男神i 2020-11-22 07:48

I\'m trying to retrieve a file from a server using SFTP (as opposed to FTPS) using Java. How can I do this?

16条回答
  •  一整个雨季
    2020-11-22 08:22

    Below is an example using Apache Common VFS:

    FileSystemOptions fsOptions = new FileSystemOptions();
    SftpFileSystemConfigBuilder.getInstance().setStrictHostKeyChecking(fsOptions, "no");
    FileSystemManager fsManager = VFS.getManager();
    String uri = "sftp://user:password@host:port/absolute-path";
    FileObject fo = fsManager.resolveFile(uri, fsOptions);
    

提交回复
热议问题