使用commons VFS检查远程服务器磁盘空间

时间:2014-07-18 09:47:40

标签: sftp diskspace vfs

我正在使用apache commons VFS将文件传输到sftp上的远程linux机器。

是否可以在传输之前检查远程机器的磁盘空间?我想仅在少于80%的磁盘空间已满时传输文件。

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

谢谢, 巴拉斯

1 个答案:

答案 0 :(得分:0)

我有类似的要求。 这里有一个最简单的解决方案。 How to find disk space of remote linux machine using Java 看看这是否可以帮到你。

相关问题