Search in sources :

Example 1 with SCPFileTransfer

use of net.schmizz.sshj.xfer.scp.SCPFileTransfer in project asterixdb by apache.

the class RemoteCopyFileAction method doPerform.

@Override
protected void doPerform() throws Exception {
    client.loadKnownHosts();
    try {
        client.connect(hostname, port);
        client.authPublickey(username, keyLocation);
        SCPFileTransfer scpft = client.newSCPFileTransfer();
        scpft.upload(srcFilePath, destFilePath);
    } finally {
        client.close();
    }
}
Also used : SCPFileTransfer(net.schmizz.sshj.xfer.scp.SCPFileTransfer)

Example 2 with SCPFileTransfer

use of net.schmizz.sshj.xfer.scp.SCPFileTransfer in project Robot by fo0.

the class SCPClient method upload.

public FileTransferData upload(String remotePath, String localPath) {
    if (client == null) {
        return null;
    }
    FileTransferData data = FileTransferData.builder().build();
    data.setLocalPath(localPath);
    data.setRemotePath(remotePath);
    data.setStarted(System.currentTimeMillis());
    SCPFileTransfer dlClient = client.newSCPFileTransfer();
    try {
        dlClient.upload(localPath, remotePath);
        data.setSuccess(true);
        data.setSize(FileUtils.sizeOf(new File(localPath)));
    } catch (Exception e) {
        Logger.error("failed to upload file " + e);
    } finally {
        data.setFinished(System.currentTimeMillis());
    }
    return data;
}
Also used : FileTransferData(com.fo0.robot.model.FileTransferData) SCPFileTransfer(net.schmizz.sshj.xfer.scp.SCPFileTransfer) File(java.io.File)

Example 3 with SCPFileTransfer

use of net.schmizz.sshj.xfer.scp.SCPFileTransfer in project Robot by fo0.

the class SCPClient method download.

public FileTransferData download(String localPath, String remotePath) {
    if (client == null) {
        return null;
    }
    FileTransferData data = FileTransferData.builder().build();
    data.setLocalPath(localPath);
    data.setRemotePath(remotePath);
    data.setStarted(System.currentTimeMillis());
    SCPFileTransfer dlClient = client.newSCPFileTransfer();
    try {
        dlClient.download(remotePath, localPath);
        data.setSuccess(true);
        data.setSize(FileUtils.sizeOf(new File(localPath)));
    } catch (Exception e) {
        Logger.error("failed to download file " + e);
    } finally {
        data.setFinished(System.currentTimeMillis());
    }
    return data;
}
Also used : FileTransferData(com.fo0.robot.model.FileTransferData) SCPFileTransfer(net.schmizz.sshj.xfer.scp.SCPFileTransfer) File(java.io.File)

Aggregations

SCPFileTransfer (net.schmizz.sshj.xfer.scp.SCPFileTransfer)3 FileTransferData (com.fo0.robot.model.FileTransferData)2 File (java.io.File)2