Search in sources :

Example 6 with FileTransferData

use of com.fo0.robot.model.FileTransferData 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

FileTransferData (com.fo0.robot.model.FileTransferData)6 File (java.io.File)4 FTPClient (com.fo0.robot.connector.FTPClient)2 KeyValue (com.fo0.robot.model.KeyValue)2 SCPFileTransfer (net.schmizz.sshj.xfer.scp.SCPFileTransfer)2 SCPClient (com.fo0.robot.connector.SCPClient)1 InputStream (java.io.InputStream)1 Test (org.junit.Test)1