Apache Commons VFS2 - 无法将FileObject创建到FTP到IIS虚拟目录

时间:2012-10-29 09:54:29

标签: ftp nullpointerexception apache-commons-vfs

我正在使用Apache Commons VFS2 API(版本2.0)来实现FTP或SFTP文件的通用实现。在我们将虚拟目录作为FTP目标之前,它一直很有效。尝试从FileObject获取OutputStream时,我得到NullpointerException。

...

DefaultFileSystemManager fileSystemManager = new DefaultFileSystemManager();
fileSystemManager.addProvider("ftp", new FtpFileProvider());

FileObject remoteObject = fileSystemManager.resolveFile(<FTP_URL>, null);

FileObject tempObject = fileSystemManager.resolveFile(remoteObject, "ftpFile.txt");

if(!tempObject.exists()){
        tempObject = fileSystemManager.createVirtualFileSystem(tempObject);     
}
//No file created by above actions so below gives null
OutputStream outputStream = tempObject.getContent().getOutputStream();

IOUtils.copy(inputStream, outputStream);

...

0 个答案:

没有答案