【问题标题】:How to read remote file from Windows to Linux with apache commons vfs?如何使用 apache commons vfs 从 Windows 读取远程文件到 Linux?
【发布时间】:2017-01-31 16:31:04
【问题描述】:

我在 Windows 上有一个文件,我想从 linux 读取这个文件。下面的代码在我尝试从 Windows 运行时运行良好,但当我尝试从 linux 运行时它给出了;

"Could not read from "file:///10.0.0.1/C$/myfolder/test.txt" because it is not a file."

这是我的代码;

    FileSystemOptions opts = new FileSystemOptions();
    DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator(opts, auth);

    FileObject fo = VFS.getManager().resolveFile(remoteFilePath, opts);

    InputStream inputStream = fo.getContent().getInputStream(); //this line throws exception

【问题讨论】:

    标签: java filesystems apache-commons


    【解决方案1】:

    我想我可能有适合你的解决方案。

    我遇到了同样的错误,并通过设置如下选项解决了它:

    private void readSFTP(){        
    // ...
    final FileObject sftpOriginObj = manager.resolveFile(ftpOrigin, getSFTPOptions());
    // ...
    }
    
        private static FileSystemOptions getSFTPOptions() throws FileSystemException {
                // Create SFTP options
                final FileSystemOptions opts = new FileSystemOptions();
    
                // SSH Key checking
                SftpFileSystemConfigBuilder.getInstance().setStrictHostKeyChecking(opts, "no");
    
                // Using the following line will cause VFS to choose File System's Root
                // as VFS's root. If I wanted to use User's home as VFS's root then set
                // 2nd method parameter to "true"
    
                // Root directory set to user home
                SftpFileSystemConfigBuilder.getInstance().setUserDirIsRoot(opts, false);
    
                // Timeout is count by Milliseconds
                SftpFileSystemConfigBuilder.getInstance().setTimeout(opts, 10000);
    
                return opts;
            }
    

    希望这会有所帮助。

    【讨论】:

      猜你喜欢
      • 2012-04-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-08-06
      • 1970-01-01
      • 2017-11-19
      相关资源
      最近更新 更多