Category Archives: apache-commons-vfs

Creating a directory in linux server using apache.commons.vfs(JAVA)

I'm able to transfer files using apache.commons.vfs(JAVA).

However I need to make directory in the server before transferring files. Refer the code below:

public static void upload(String hostName, String username, String password, String localFilePath, String remoteFilePath) {

    File file = new File(localFilePath);
    if (!file.exists())
        throw new RuntimeException("Error. Local file not found");

    StandardFileSystemManager manager = new StandardFileSystemManager();

    try {

        // Create local file object
        FileObject localFile = manager.resolveFile(file.getAbsolutePath());

        // Create remote file object
        FileObject remoteFile = manager.resolveFile(createConnectionString(hostName, username, password, remoteFilePath), createDefaultOptions());
         * use createDefaultOptions() in place of fsOptions for all default
         * options - Ashok.
        // Copy local file to sftp server
        remoteFile.copyFrom(localFile, Selectors.SELECT_SELF);

        System.out.println("File upload success");
    } catch (Exception e) {
        throw new RuntimeException(e);
    } finally {

org.apache.commons.vfs2.FileSystemException: Could not close the output stream

I am using VFS 2.0 for implementing SFTP for my application. I have a single Thread which actually picks up the file and do SFTP. 98% of the time it works. But I have observed there are few cases where SFTP is getting failed with below exception..

Caused by: org.apache.commons.vfs2.FileSystemException: Could not close the output stream for file "sftp://*******************/Test.csv".
    [null,null]at org.apache.commons.vfs2.provider.DefaultFileContent$FileContentOutputStream.close(
    [null,null]at org.apache.commons.vfs2.FileUtil.copyContent(
    [null,null]at org.apache.commons.vfs2.provider.AbstractFileObject.copyFrom(
    [null,null]... 3 more
Caused by: inputstream is closed
    [null,null]at com.jcraft.jsch.ChannelSftp.fill(
    [null,null]at com.jcraft.jsch.ChannelSftp.header(
    [null,null]at com.jcraft.jsch.ChannelSftp.checkStatus(
    [null,null]at com.jcraft.jsch.ChannelSftp._sendCLOSE(
    [null,null]at com.jcraft.jsch.ChannelSftp.access$400(
    [null,null]at com.jcraft.jsch.ChannelSftp$1.close(
    [null,null]at org.apache.commons.vfs2.util.MonitorOutputStream.close(
    [null,null]at org.apache.commons.vfs2.util.MonitorOutputStream.close(
    [null,null]at org.apache.commons.vfs2.provider.DefaultFileContent$FileContentOutputStream.close(
    [null,null]... 5 more

Please suggest what could be the possible reason for the above exception.

How do I use JCIFS with apache VFS to access an SMB URL – part 2?

I had the same problem: How do I use JCIFS with apache VFS to access an SMB URL?

... after including commons-vfs-sandbox-2.1-SNAPSHOT.jar in the classpath I now get this exception:

Exception in thread "main" org.apache.commons.vfs2.FileSystemException: Could not determine the type of file "smb://".
    at org.apache.commons.vfs2.provider.AbstractFileObject.attach(
    at org.apache.commons.vfs2.provider.AbstractFileObject.getType(
    at org.apache.commons.vfs2.provider.AbstractFileObject.exists(
    at VFSTest.main(
Caused by: jcifs.smb.SmbAuthException: Logon failure: account currently disabled.
    at jcifs.smb.SmbTransport.checkStatus(
    at jcifs.smb.SmbTransport.send(
    at jcifs.smb.SmbSession.sessionSetup(
    at jcifs.smb.SmbSession.send(
    at jcifs.smb.SmbTree.treeConnect(
    at jcifs.smb.SmbFile.doConnect(
    at jcifs.smb.SmbFile.connect(
    at jcifs.smb.SmbFile.connect0(
    at jcifs.smb.SmbFile.queryPath(
    at jcifs.smb.SmbFile.exists(
    at jcifs.smb.SmbFile.isDirectory(
    at org.apache.commons.vfs2.provider.smb.SmbFileObject.createSmbFile(
    at org.apache.commons.vfs2.provider.smb.SmbFileObject.doAttach(
    at org.apache.commons.vfs2.provider.AbstractFileObject.attach(
    ... 3 more

Please advice.