node-rsync
node-rsync copied to clipboard
When I use rsync in winows system, there is an unsolvable error
env: process.platform: win32 node version: v10.x.x
my code
const workDir = path.resolve('.')
console.log(chalk.red(`This platform is ${process.platform}\n`))
const stdoutHandler = function(data) {
console.log(chalk.green('stdoutHandler: '))
console.log(data.toString())
console.log(chalk.green('================\n'))
}
const stderrHandler = function() {
console.log(chalk.red('stderrHandler: '))
console.log(data.toString())
console.log(chalk.red('================\n'))
}
module.exports = async (txt) => {
const outFile = path.resolve(workDir, `testSync.txt`)
await fse.outputFile(outFile, txt)
const cmd = new Rsync()
.flags('avz')
.shell('ssh')
.source(outFile)
.destination('name@server:/home/appadmin/cli');
cmd.execute(function(error, code, cmd) {
console.log('code: ', code)
if (error) {
console.error(error)
console.log('error: ', cmd)
process.exit(1)
}
console.log('All done executing: ', cmd);
}, stdoutHandler, stderrHandler);
}
cmd output content:
$ retailo2o-cli test 000
This platform is win32
stdoutHandler:
'rsync' �����ڲ����ⲿ���Ҳ���ǿ����еij���
���������ļ���
================
code: 1
Error: rsync exited with code 1
at Rsync.<anonymous> (D:\nvm\v10.15.1\node_global\node_modules\retailo2o-cli\node_modules\rsync\rsync.js:525:21)
at ChildProcess.emit (events.js:189:13)
at maybeClose (internal/child_process.js:970:16)
at Process.ChildProcess._handle.onexit (internal/child_process.js:259:5)
error: rsync -avz --rsh=ssh /workspace/coupon/testSync.txt name@server:/home/appadmin/cli
I have the same problem
Same problem here. It seems like OS should support rsync, am I right @mattijs ?
Same issue here
no rsync in your windows, you have to download 'cwrsync' , then put the 'cwrsync' in your src, then init Rsyhnc instance use executable params
let rsyncPath = path.resolve('libs/cwrsync/bin/rsync.exe') let rsyncConfig={ executable:rsyncPath } var rsync = new Rsync(rsyncConfig)
notice: When you setup 'source' and 'destination' of Rsync,you have to turn windows path into cgwin path,
example: your source is "C:\sourceFolder" , you need turn into "/cygdrive/C/sourceFolder"
The follow code maybe can help you:
function transPathToCygwin(winPath) { if (process.platform == "win32") { if (winPath[1] == ":") { let diskSign = winPath[0] winPath = winPath.substr(2) winPath = winPath.split(path.sep).join(path.posix.sep); let posixPath = "/cygdrive/" + diskSign + winPath return posixPath } } else { return winPath } }