1

I'm using Apache Commons VFS2 API (version 2.0) for a generic implementation to FTP or SFTP files. It has been working great till we had Virtual Directories as FTP destinations. I get NullpointerException trying to obtain an OutputStream from the FileObject.

...

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);

...

f_puras
  • 2,521
  • 4
  • 33
  • 38
  • how does FTP_URL look exactly, is it containing a virtual folder or the root of the server? Where is the virtual root? (BTW: you dont need to create the file if you open the output stream to it this will be done automatically). – eckes Jan 06 '15 at 00:07

0 Answers0