Created
January 10, 2018 05:28
-
-
Save vnoder/33244d433a2830187aa004645b66a85d to your computer and use it in GitHub Desktop.
rsync file with node.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * 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