View Single Post
  #1440  
Old 30.06.2020, 20:36
Rabelux Rabelux is offline
Ultra Loader
 
Join Date: Oct 2018
Posts: 47
Lightbulb

As it took me a few hours to get it done im posting my code for anyone who wants to send a finished download to a remote machine via scp.
This is a follow-up post of my last post in Dec '19.

OS: Linux with public key auth on remote server
Code:
disablePermissionChecks();
if (link.isFinished()) {
    var sourceFile = link.getDownloadPath();
    var result = callSync("scp", "-P <portnr>", sourceFile, "<user>@<IP_of_destination>:/<filepath>");
    var exitcode = callSync("sh", "-c", "echo $?").trim();
    log("scp-output: " + result);
    log("Exit Code: " + exitcode);
    if (exitcode == "0") {
        deleteFile(sourceFile, false); //false=non-recursive
        log("DELETED " + link.getName());
    }
    if (package.isFinished()) package.remove();
}
I guess there is still room for optimization, for example a more elegant solution might be
Code:
callSync("sh", "-c", "scp -P <portnr> " + sourceFile + " <user>@<IP_of_destination>:/<filepath> && rm " + sourceFile);
but I'm happy with it the way it is.
Reply With Quote