...
No Format |
---|
private FileSystemManager fsManager = VFS.getManager(); |
the getManager() method probably returned a \[http://commons.apache.org/vfs/apidocs/org/apache/commons/vfs/impl/StandardFileSystemManager.html StandardFileSystemManager\] which extends the DefaultFileSystemManager class and implements the FileSystemManager interface.unmigrated-wiki-markup Wiki Markup
What you are probably after is the \[http://commons.apache.org/vfs/apidocs/org/apache/commons/vfs/impl/DefaultFileSystemManager.html#close() close()\] method of the DefaultFileSystemManager to clean up any temporary files and close all providers. Cast the FileSystemManager to a DefaultFileSystemManager access the close() method like this:like this:
No Format |
---|
((DefaultFileSystemManager) fsManager).close();
|
How can I connect to an SFTP server even if there is no entry in known_hosts?
JSch, the library that provides VFS with SFTP functionality, checks that the host one tries connecting to is a known host, i.e. has an entry in the file $HOME/.ssh/known_hosts. By default, connections to unkown hosts are rejected by throwing an exception. You can change this behaviour by specifying the strict host key checking option:
No Format |
---|
FileSystemOptions opts = new FileSystemOptions();
SftpFileSystemConfigBuilder.getInstance().setStrictHostKeyChecking(opts, "no");
FileSystemManager fsManager = VFS.getManager();
FileObject foo = fsManager.resolveFile("sftp://login:password@host/foo.bar", opts);
// Do some stuff
foo.close(); |
No Format |
((DefaultFileSystemManager) fsManager).close(); |