Skip to content
This repository has been archived by the owner on Jul 11, 2023. It is now read-only.

Custom port ? #66

Open
HugoHeneault opened this issue Oct 9, 2018 · 2 comments
Open

Custom port ? #66

HugoHeneault opened this issue Oct 9, 2018 · 2 comments

Comments

@HugoHeneault
Copy link

Hi there,

I'm trying to use a custom port for my rsync script.
Here's what I use :

const rsyncArgs = new Rsync()
            .flags('avz')
            .set('e', `ssh -p 5000`)
            .set('progress')
            .set('no-motd')
            .source(`${directory}/`)
            .destination(`${stage.server.user}@${stage.server.host}:${stage.server.directory}`)

const rsync = spawn('rsync', rsyncArgs.args());

And here the command generated by calling rsyncArgs.command():

rsync -avz -e "ssh -p 5000" --progress --no-motd /private/var/www/dir user@host:public_html

But my script exits with:

rsync: Failed to exec ssh -p 5000: No such file or directory (2)
rsync error: error in IPC code (code 14) at pipe.c(85) [sender=3.1.3]
rsync: connection unexpectedly closed (0 bytes received so far) [sender]
rsync error: error in rsync protocol data stream (code 12) at io.c(226) [sender=3.1.3]

When I run the command in the terminal, everything works smoothly. So the request is generating fine, but isn't running in with the spawn methods...

@HugoHeneault
Copy link
Author

HugoHeneault commented Oct 9, 2018

So after quite a while I found a workaround!

Before calling spawn, I override the --rsh arg to remove the quotes and it works.

Here's my code:

const rsyncArgs = new Rsync()
            // set your own rsync params here
            .flags('avz')
            .shell('ssh')
            .set('progress')
            .set('no-motd')
            .source(`${directory}/`)
            .destination(`${stage.server.user}@${stage.server.host}:${stage.server.directory}`)

        // fix for port here
        const args = rsyncArgs.args()
        if (stage.server.port) {
            const index = args.findIndex(arg => arg === '--rsh=ssh')
            args[index] = `--rsh=ssh -p ${stage.server.port}`
        }

        const rsync = spawn('rsync', args);

@jasonschmedes
Copy link

Use rsync.execute. Or look at how rsync.execute uses spawn to run the command: https://github.com/mattijs/node-rsync/blob/master/rsync.js#L481

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants