Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to copy a folder over SSH with Gulp?

I have been experimenting with gulp lately, and have had a lot of success, but now I am stumped.

I have gulp building everything, and I want to upload a folder afterwards. I have created a deploy task for this using gulp-scp2:

gulp.task('deploy', ['clean', 'build'], function() {
    var privateKeyPath = getUserHome() + '/.ssh/id_rsa';

    gulp.src('public/dist')
        .pipe(scp({
            host: 'myhost',
            username: 'user',
            dest: '/home/user/test',
            agent: process.env['SSH_AUTH_SOCK'],
            agentForward: true,
            watch: function(client) {
                client.on('write', function(o) {
                    console.log('write %s', o.destination);
                });
            }
        })).on('error', function(err) {
            console.log(err);
        });
});

Unfortunately, when I do this, I get the following error:

Error: Content should be buffer or file descriptor

How can I copy a folder over SSH using gulp?

like image 479
NT3RP Avatar asked Jul 08 '14 19:07

NT3RP


1 Answers

I did end up finding a solution by leveraging the node scp2 library:

scpClient = require('scp2');

gulp.task('scp', [], function (cb) {
    scpClient.scp('local_folder', {
        "host": "remote_host",
        "port": "remote_port",
        "username": "username_on_remote",
        "path": "/path/on/remote",
        "agent": process.env["SSH_AUTH_SOCK"],
        "agentForward": true
    }, cb)
});
like image 84
NT3RP Avatar answered Sep 22 '22 06:09

NT3RP