0

I am using apache commons VFS to transfer the files to remote linux machine on sftp.

Is it possible to check the disk space of remote machine before transferring?I want to transfer the file only if less than 80% of the disk space is full.

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

    StandardFileSystemManager manager = new StandardFileSystemManager();

    try {
        manager.init();

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

        // Create remote file object
        FileObject remoteFile = manager.resolveFile(createConnectionString(hostName, username, password, remoteFilePath), createDefaultOptions());

        // 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 {
        manager.close();
    }

Thanks, Bharath

user608020
  • 313
  • 4
  • 15

1 Answers1

0

I had similar requirement. Got an easiest solution here. How to find disk space of remote linux machine using Java See if this can help you.

Community
  • 1
  • 1
devThoughts
  • 820
  • 1
  • 12
  • 18