Skip to content

Instantly share code, notes, and snippets.

@vnoder
Created January 10, 2018 05:28
Show Gist options
  • Select an option

  • Save vnoder/33244d433a2830187aa004645b66a85d to your computer and use it in GitHub Desktop.

Select an option

Save vnoder/33244d433a2830187aa004645b66a85d to your computer and use it in GitHub Desktop.
rsync file with node.js
/**
* Created by vd on 10/01/18.
*/
'use strict';
const shell = require('shelljs');
/**
* rsync file (must config public key, passport is not supported)
*
* if exec success, result code is 0
* @param src - local file path(file or dir)
* @param dest - dest
* @param port - remote port
* @param exclude
* @param silent
*/
function sshRsyncFile(src, dest, port = 22, exclude = '.DS_Store', silent = true) {
let silentState = shell.config.silent;
shell.config.silent = silent;
let result = shell.exec(`rsync -avzP --exclude='${exclude}' -e 'ssh -p ${port}' ${src} ${dest}`);
shell.config.silent = silentState;
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment