Giter Club home page Giter Club logo

gulp-ssh's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

gulp-ssh's Issues

Best way to close connection?

I need to run some shell commands, but if I run close after the shell command, the close runs before the shell commands run. Is there a way to best practice for closing the connection when you are done or when the shell commands are finished?

On the examples there is a .pipe(gulp.dest()) but that is not closing the connection.

ssh.shell(['cd ~/bom-test', 'rm -rf node_modules/', 'npm install --production', 'exit']);

the npm command doesn't finish if the connection is closed prematurely.

_stream_writable.js: TypeError: object is not a function

Hello,

I'm trying to copy just an index.html file from my machine to the machine server, and I'm getting the following error [1].

This is my simple task [2] and I'm using Ubuntu 14.04 64 bits and NodeJS v0.12.7.

[1]

duall@duall-dev:~/dev/git/duallsite$ gulp client:publish
[12:41:14] Using gulpfile ~/dev/git/duallsite/gulpfile.js
[12:41:14] Starting 'client:publish'...
[12:41:15] gulp-ssh :: Connect...
[12:41:17] gulp-ssh :: Ready
[12:41:17] Preparing to write "/home/ubuntu/__SITE_TMP/index.html"
[12:41:18] Writing '/home/ubuntu/__SITE_TMP/index.html'
[12:41:18] Finished writing '/home/ubuntu/__SITE_TMP/index.html'
_stream_writable.js:313
    cb(er);
    ^
TypeError: object is not a function
    at onwriteError (_stream_writable.js:313:5)
    at onwrite (_stream_writable.js:335:5)
    at WritableState.onwrite (_stream_writable.js:105:5)
    at /home/duall/dev/git/duallsite/node_modules/gulp-ssh/node_modules/ssh2/node_modules/ssh2-streams/lib/sftp.js:2752:14
    at state.requests.(anonymous function).cb (/home/duall/dev/git/duallsite/node_modules/gulp-ssh/node_modules/ssh2/node_modules/ssh2-streams/lib/sftp.js:960:15)
    at SFTPStream._cleanup (/home/duall/dev/git/duallsite/node_modules/gulp-ssh/node_modules/ssh2/node_modules/ssh2-streams/lib/sftp.js:190:38)
    at SFTPStream.end (/home/duall/dev/git/duallsite/node_modules/gulp-ssh/node_modules/ssh2/node_modules/ssh2-streams/lib/sftp.js:160:8)
    at SFTPWrapper.end (/home/duall/dev/git/duallsite/node_modules/gulp-ssh/node_modules/ssh2/lib/SFTPWrapper.js:29:23)
    at end (/home/duall/dev/git/duallsite/node_modules/gulp-ssh/index.js:253:18)
    at DestroyableTransform._flush (/home/duall/dev/git/duallsite/node_modules/gulp-ssh/index.js:286:5)

[2]

gulp.task('client:publish', function () {
    return gulp
        .src([paths.dist + '/index.html'])
        .pipe(gulpSSH.dest('/home/ubuntu/__SITE_TMP/'));
});

Is gulp-ssh compatible with this environment?

Thank you!

gulpssh.exec "npm install" keep hanging

Firstly Thank You!

I am trying to automate my deployments and using: "gulp-ssh": "^0.3.3" and have something like this:

ssh.exec [ "cd /var/www/release_folder", "git pull", "npm install"], {filePath: 'gulp.ssh.log'}

Output:

[21:55:48] gulp-ssh :: Executing :: cd /var/www/release_folder
[21:55:49] gulp-ssh :: Executing :: npm install
[21:55:50] 'api:deploy' errored after 16 s
[21:55:50] Error in plugin 'gulp-ssh'
Message:
    npm

It keeps hanging and no error in my log file. Am I missing something? If I run the cd /var/www/release_folder && npm install command manually in my shell it works perfect.

Remote files are written with absolute local path

When uploading using gulpSSH.dest, the remote path includes the entire local path.

So a project stored at
/home/user/projects/api/index.js
/home/user/projects/api/lib/util.js

gets deployed to the remote dest('/home/user/api') as
/home/user/api/home/user/projects/api/index.js
/home/user/api/home/user/projects/api/lib/util.js

instead of just
/home/user/api/index.js
/home/user/api/lib/util.js

Example:

gulp.task('deploy:staging:copy', function(){
    return gulp
        .src(['**/*'], { base: './' })
        .pipe(gulpSSH.dest('/home/user/api'));
});

I made a temporary work-around by adding a stream filter, as mentioned in #44 , which switches the file path for the relative file path:

gulp.task('deploy:staging:copy', function(){
    return gulp
        .src(['**/*'], { base: './' })
        .pipe(require('stream-filter').obj(function(file) {
            file.path = file.relative;
            return file;
        }))
        .pipe(gulpSSH.dest('/home/user/api'));
});

But this seems inefficient and contrary to what is expected.

Executing remote `bash` scrip

Hello there!

I am having an issue with executing a remote bash script. The script itself (attached below) works like a charm on the server.

#!/bin/bash

 #
 #   build cipchduyg0000x6royxfkchrn @ Sun Jun 12 2016 13:01:46 GMT+0200 (CEST)
 #

 DIR = /var/www/meteor/pepkalc/
 tar xvfz /var/www/meteor/pepkalc/pepkalc.tar.gz
 if [ -d $DIR ]; then
    cd /var/www/meteor/pepkalc/bundle/programs/server
    rm -rf node_modules
    npm install --silent
    # rm -rf /var/www/meteor/pepkalc/pepkalc.tar.gz
    chown -R meteor:meteor /var/www/meteor/pepkalc/
    chmod -R 755 /var/www/meteor/pepkalc/
    restart pepkalc || start pepkalc
    exit 0
 fi
 exit 0

I have tried both exec and shell with gulp-ssh in the following gulp task,

gulp.task('deploy:install', function() {
    return ssh.shell(
            ['bash -f ' + sandboxDir + 'install.com'], {
                filePath: buildVersion + '.log'
            })
        .pipe(gulp.dest('logs'));
});

however, gulp-ssh shell simply hangs upon the execution:

kamil@Kamils-iMac:~/Development/meteor/pepkalc/.install$ gulp deploy:install
[13:07:15] Using gulpfile ~/Development/meteor/pepkalc/.install/gulpfile.js
[13:07:15] Starting 'deploy:install'...
[13:07:16] gulp-ssh :: shell :: bash -f /var/www/meteor/pepkalc/install.com

whereas gulp-ssh exec reports an error,

kamil@Kamils-iMac:~/Development/meteor/pepkalc/.install$ gulp deploy:install
[13:08:32] Using gulpfile ~/Development/meteor/pepkalc/.install/gulpfile.js
[13:08:32] Starting 'deploy:install'...
[13:08:33] gulp-ssh :: Executing :: bash -f /var/www/meteor/pepkalc/install.com

events.js:141
      throw er; // Unhandled 'error' event
      ^
Error: /var/www/meteor/pepkalc/install.com: line 9: DIR: command not found

Question is, what's wrong with my scripting?

Howto use in combination with a ssh-agent?

I am using gulp-ssh within my gulpfile.js which is located inside a Vagrant box.
I have enabled SSH forwarding agent to this box with the setting config.ssh.forward_agent = true.

If I manually SSH into the box: vagrant ssh. And once on the terminal inside the box do a ssh myuser@myotherhost I get connected without a password prompt. So far so good.

But how can I configure Gulp-SSH to make use of this forwarded private key also? Because I can't configure the password in gulp-ssh and also I can't configure the private key, since it is not available inside the vagrant box.

Any ideas/help is welcome.

Only transfer files that are timestamped as newer?

I'm trying to use gulp-ssh in conjunction with gulp-newer to only transfer files that are stamped as newer than the last transfer. Am I missing something here? This block transfers everything, not just updated files.

gulp.task('deploy-prod', function () {
return gulp.src(['./'+build_dir+'wp-content//*'])
.pipe(newer(prod_content_dir+'
/*'))
.pipe(gulpSSH.dest(prod_content_dir))
});

Filesystem `fs` modules is missing in "readme.md" example

gulpfile.js:10
    privateKey: fs.readFileSync('/Users/zensh/.ssh/id_rsa')

ReferenceError: fs is not defined
    at Object.<anonymous> (gulpfile.js:10:15)
    ...

I think would be nice, example would just work when people start to play with it.

Callback function

Hi, thanks for the plugin.

Is it possible to add a callback function after the SSH connection is closed?

ssh from windows to linux fails

gulpfile:

var fs = require('fs');
var GulpSSH = require('gulp-ssh');

var sshConfig = {
    host: config.deploy_host,
    port: 22,
    username: config.deploy_host_username,
    privateKey: fs.readFileSync(config.deploy_host_private_key)
};

var ssh = new GulpSSH({
    ignoreErrors: false,
    sshConfig: sshConfig
});

gulp.task('deploy1', function () {
    return gulp
        .src(['*/**', '!**/node_modules/**', '!local/**', '!node_heapdumps'])
        .pipe(ssh.dest(config.deploy_host_dest))
});

gulp.task('deploy2', function () {
    return gulp
        .src(['main.js'])
        .pipe(ssh.sftp('write', config.deploy_host_dest + '/main.js')) // dest ending with /
});

Deploying from Widnows (Vista) to linux machine fails like this - hanging:

    [13:56:47] Using gulpfile c:\project\git\project\gulpfile.js
    [13:56:47] Starting 'deploy'...
    [13:56:47] gulp-ssh :: Connect...
    [13:56:49] gulp-ssh :: Ready
    [13:56:50] Preparing to write "\usr\honzajde\project\main.js"

Note that line: Preparing to write "\usr\honzajde\project\main.js has backslashes...

sftp read/write all files in folder

is it possible to read all files in a folder, or better read/copy a folder recursive with all subfolder/subfiles via sftp? i tried different *-combination or {recursive:true} as options, but that did not work.
btw: which options are available by the sftp-api (command, filePath, options)?
Tnx.

exec cd don`t work

running this example:

gulp.task('test2', function () {
  return gulpSSH
    .exec(['date','hostname', 'cd /opt/app/', 'pwd', 'ls -a'],
             {filePath: 'commands.log'})
    .pipe(gulp.dest('logs'));
});

leaves in the log:

Fri Mar 20 15:12:35 UTC 2015
s21
/home/operador
.
..
.bash_history
.bash_logout
.bash_profile
.bashrc

that means, that everything works fine unless the "change directory" command.
Can you help me?

回调执行问题

CODE:

gulp.task('test', function() {

   gulp.src('lst/*.lst')
        .pipe(foreach(function(stream, file){
        var fileName = path.basename(file.path),
            fileContent = String(file.contents).split(':');

        if (fileContent[0] === 'file') {
            var ssh = new GulpSSH({
                ignoreErrors: false,
                sshConfig: {
                    host: ZipServerCfg.UAT.WEB.host,
                    port: 22,
                    username: ZipServerCfg.UAT.WEB.user,
                    password: ZipServerCfg.UAT.WEB.pass
                }
            });
            return stream.pipe(ssh.sftp('write', ZipServerCfg.UAT.WEB.lstUploadFiles+fileName)).on('finish', function(){
                    log(color.green(fileName) + ' Uploaded');
                    ssh.shell(['cd update', 'sh pack_ver.sh '+fileName, 'exit'], {filePath: fileName+'.log'}).on('end', function(){
                            log(color.green(fileName) + ' Finished Packing');
                            ssh.sftp('read', ZipServerCfg.UAT.WEB.tarDownFiles+(fileName.substring(0, fileName.length-4)+'.tar.gz')).pipe(gulp.dest('tar'));
                        }).pipe(gulp.dest('logs'));
            });
            //return stream;
        }
    }));
});

想达到的效果:

循环所有 LST 文件 - 上传 LST 文件 - 执行打包 - 下载打包文件

现在问题:

image
会一直卡在这里..不知道怎么去描述这个问题出在哪里了..

Sudo commands and shell sessions

Hi

Are there any plans to integrate sudo and multiple commands via shell2 shell's function? Most use cases require the use of sudo often with password prompt plus the running of multiple commands in one shell session.

Thanks

gulp-ssh not working anymore

Hi, gulp-ssh was working without troubles but after running npm install(npm install) breaks with error.


_stream_writable.js:313
    cb(er);
    ^
TypeError: object is not a function
    at onwriteError (_stream_writable.js:313:5)
    at onwrite (_stream_writable.js:335:5)
    at WritableState.onwrite (_stream_writable.js:105:5)
    at c:\_projekte\Products\WIGeoWeb3_ANWR\node_modules\gulp-ssh\node_modules\ssh2\node_modules\ssh2-streams\lib\sftp.js:2752:14
    at state.requests.(anonymous function).cb (c:\_projekte\Products\WIGeoWeb3_ANWR\node_modules\gulp-ssh\node_modules\ssh2\node_modules\ssh2-streams\lib\sftp.js:960:15)
    at SFTPStream._cleanup (c:\_projekte\Products\WIGeoWeb3_ANWR\node_modules\gulp-ssh\node_modules\ssh2\node_modules\ssh2-streams\lib\sftp.js:190:38)
    at SFTPStream.end (c:\_projekte\Products\WIGeoWeb3_ANWR\node_modules\gulp-ssh\node_modules\ssh2\node_modules\ssh2-streams\lib\sftp.js:160:8)
    at SFTPWrapper.end (c:\_projekte\Products\WIGeoWeb3_ANWR\node_modules\gulp-ssh\node_modules\ssh2\lib\SFTPWrapper.js:29:23)
    at WriteStream. (c:\_projekte\Products\WIGeoWeb3_ANWR\node_modules\gulp-ssh\index.js:175:20)
    at WriteStream.emit (events.js:129:20)

Seems like problem comes from the ssh2 node module. Any help would be great!
Thanks for the nice gulp plugin :)

Error : copy files !

when I copied the files to remote server , I received the error messages ....

how can I solve this problem~ thx

===== gulp code =====
gulp.task('deploy:copy', ['deploy:clean'], function () {
return gulp
.src([conf.paths.dist + '/**'])
.pipe(gulpSSH.dest('/dist'));

===== error info =====
[17:43:31] Error in plugin 'gulp-ssh'
Message:
Failure
Details:
code: 4
lang:

release management?

Hello, thanks to all contributors!

Looking at Grunt SSH Deploy, it has some features to help manage different releases. Meaning, it deploys newest version, but can keep last few releases as well, and you can revert back to to those!
It must be some symlink job.

Is that feature available here?

Suggestion: automatically look in user directory for private key?

Hi. Just a quick suggestion. Your current README shows a hard-coded path to the user directory, but I need to write a Gulpfile that will work regardless of user or machine, so I can't hard-code that. After a bit of trial and error, I found you can use Node's os.homedir() to avoid hard-coding the path. I wonder if this (below) might be a better starting point for the README? (Or even a default place to look if no privateKey was specified...)

privateKey: fs.readFileSync(require('os').homedir() + '/.ssh/id_rsa')

Thanks!

Connection closes without any warning

Guys,
I want to execute some commands on a remote server that I'm connecting through SSH with private/public keys.

The configuration is pretty basic:

gulpSSH = require('gulp-ssh')({
  ignoreErrors: false,
  sshConfig: {
    // config.ssh is an Object that have hostname and username properties
    host: config.ssh.hostname,
    username: config.ssh.username,
    port: 22
  }
});

and the task, the in the same basic manner

gulp.task('deploy-run', function() {
  return gulpSSH
    .shell(['mkdir x'], {filePath: 'ssh.log'})
    .pipe(dest('.logs'));
});

what console outputs when I type gulp deploy-run is

$ gulp deploy-run
Using gulpfile /<path-to-project>/gulpfile.js
Starting 'deploy-run'...
gulp-ssh :: Connect...
gulp-ssh :: Close

ssh.log file is created in ./.logs but it has no content, unfortunately :(

Is there any issue with gulp-ssh or the configuration?

Any way to log data during each command instead of the full data log at the end?

I have a gulp-ssh task that is setup like this:

return gulpSSH
    .shell(['cd /mydir', 'git pull', 'npm install', 'gulp build'])
    .on('data', function(file) {
        console.log(file.contents.toString());
    });

The problem here is that ALL the data is logged AFTER all the tasks have run. Is there any way to display the data/logs as the tasks are being executed?

Thanks for the script and any suggestions!

Can't change directory

Hello,
I can't manage to change directory with gulp-ssh :(

I want to create a gulp task to :

  1. connect my server in ssh
  2. change to correct directory
  3. git pull
  4. gulp build

point 2) doesnt work, so everything else is not working ... what's the point ? thx

Question: Executing global modules?

I've been trying to execute commands of global modules. Examples being npm and pm2. Both are installed on the host.

I've tried all of the following commands, but none have worked. When logging into the machine, these commands work

npm install --production, pm2 start, $(which pm2) start

Errors:

events.js:160
      throw er; // Unhandled 'error' event
      ^
Error: bash: npm: command not found
events.js:160
      throw er; // Unhandled 'error' event
      ^
Error: bash: pm2: command not found

How to navigate folders on the remote?

Hi, how would you navigate your remote? Tried using cd with exec but no luck, it returns whatever is in the root, not my subfolder.

gulp.task('exec', function () {
    return gulpSSH
        .exec(['cd subfolder/', 'ls -a', 'pwd'], {filePath: 'commands.log'})
        .pipe(gulp.dest('logs'));
});

In the end I want to do

  1. gulp build
  2. upload /dist using gulp-ssh to a specific folder on my remote

Selective disable of echo in shell mode for password entry?

This may not be an issue as much as a feature request (or my misunderstanding of the shell command). When I launch a shell sequence, example:

gulp.task('remoteList', function () {
  return gulpSSH
    .shell([ 'sudo ls -a']).on('ssh2Data', function(chunk) {
      process.stdout.write(chunk);
  });
});

A prompt seems to appear for sudo password entry but it echoes my password in the terminal. Is there a way to disable the echo for password prompts? It looks like the underlying SSH2 supports options for that through pseudo tty but I don't see that is passed through from gulp-ssh. Or am I totally getting the shell setup wrong with code above? Thanks. This is my last missing piece to achieve near Fabric like experience with Gulp.

sftp does not work with agentForward

Hi,

Here's the config:

var gulpSSH = require('gulp-ssh')({
    ignoreErrors: false,
    sshConfig: {
        host: 'myhost',
        username: 'root',
        port: 22,
        agent: process.env["SSH_AUTH_SOCK"],
        agentForward: true
    }
});

With this config gulpSSH.shell() works great! But gulpSSH.sftp() does NOT! It freezes on 'gulp-ssh :: Connect...' and then 'Timed out while waiting for handshake'

Sudo for Exec

Orignal ssh2 supports sudo comands by allocating pseudo-tty session via passing {pty : true}.
The required password is then written to the stream returned via callback of exec function. e.g:

...exec('<command>', function(err, stream) {
      stream.write(password + "\n")
}). 

To be able to do so I offer to pipe outstream in gulp-ssh exec function (outStream.pipe(stream)).

function execCommand() {
...gutil.log(packageName + ' :: Executing :: ' + command)
        ssh.exec(command, options, function (err, stream) {
            if (err) return outStream.emit('error', new gutil.PluginError(packageName, err))           
            outStream.pipe(stream)  //possible fix
            stream
                   .on('data',....
}

The described pipe will allow to simply write smth like this

gulp.task("restart-pm2-task", function(callback) {
    ssh.exec(['sudo <your command>'],{pty : true}).write(password + "\n")

I suppose it's a bit of a crutch, so I am just reporting of a problem and giving you a simple solution. If ok, i can make a pull request with the described changes

Utilize ~/.ssh/config

Is it possible to utilize the .ssh config? I don't think it is, but wanted to be sure I was not missing something. Thanks!

Copy an entire folder from local to remote

Hi.
I'm tryingo to copy a local folder to a remote server with the following syntax:

gulp.task('deploy:bootstrap', () =>
  gulp.src(['./dist/bootstrap-2.3.2/'])
    .pipe(gulpSSH.dest('/home/user/dest/'))
);

But I get the following:

user@host:$ gulp deploy:bootstrap
[11:47:29] Using gulpfile /home/user/project/gulpfile.js
[11:47:29] Starting 'deploy:bootstrap'...
[11:47:29] "/home/user/project/dist/bootstrap-2.3.2" has no content. Skipping.
[11:47:29] Finished 'deploy:bootstrap' after 22 ms

My folder structure is:

bootstrap-2.3.2/
├── css
│   ├── bootstrap.min.css
│   └── bootstrap-responsive.min.css
├── img
│   ├── glyphicons-halflings.png
│   └── glyphicons-halflings-white.png
└── js
    └── bootstrap.min.js

Why it is treated as it were empty?

Thank you.

End Stream is never getting called

Relevant gulfile.js bit

gulp.task('vm-deploy', ['vm-build'], function(){
  var gulpSSH = new Ssh({ignoreErrors: false, sshConfig: vmConfig});
  try {
    return gulpSSH.shell(['sudo ansible-playbook gulp-vm.yml --connection=local', 'logout'], {filePath:'sshvmlog.log'})
    .pipe(gulp.dest('log'));
  }
  catch(e){
    console.log(e);
  }

I threw a console log in the index.js for gulp-ssh under the endStream callback to confirm that it never gets called. What's up?

gulp-ssh.dest doesn't support merge-streams

Gulp fails when trying to merge multiple streams of gulp-ssh.dest. Error "no writecb in Transform class" occurs when trying to run the following gulp-task (merging 1 stream for simplicity)

gulp.task("copy-to-remote", function() {
     var t = gulp
        .src(src)
        .pipe(gulpSSH.dest(dest))
    return merge(t)
})

Here's the traceback.

[15:53:06] gulp-ssh :: Connect...
[15:53:06] gulp-ssh :: Ready
[15:53:06] Preparing to write "/home/support/1/1.test"
[15:53:06] Writing '/home/support/1/1.test'
[15:53:06] Finished writing '/home/support/1/1.test'
[15:53:06] Preparing to write "/home/support/1/123/55.txt"
[15:53:06] Writing '/home/support/1/123/55.txt'
[15:53:06] Finished writing '/home/support/1/123/55.txt'

events.js:72
        throw er; // Unhandled 'error' event
              ^
Error: no writecb in Transform class
    at afterTransform (/home/support/project/node_modules/gulp-ssh/node_modules/through2/node_modules/readable-stream/lib/_stream_transform.js:75:33)
    at TransformState.afterTransform (/home/support/project/node_modules/gulp-ssh/node_modules/through2/node_modules/readable-stream/lib/_stream_transform.js:59:12)
    at end (/home/support/project/node_modules/gulp-ssh/index.js:259:9)
    at WriteStream.done (/home/support/project/node_modules/gulp-ssh/index.js:281:37)
    at WriteStream.emit (events.js:95:17)
    at /home/support/project/node_modules/gulp-ssh/node_modules/ssh2/node_modules/ssh2-streams/lib/sftp.js:2656:14
    at SFTPStream._cleanup (/home/support/project/node_modules/gulp-ssh/node_modules/ssh2/node_modules/ssh2-streams/lib/sftp.js:193:38)
    at SFTPStream.onFinish (/home/support/project/node_modules/gulp-ssh/node_modules/ssh2/node_modules/ssh2-streams/lib/sftp.js:159:10)
    at SFTPStream.emit (events.js:117:20)
    at finishMaybe (_stream_writable.js:359:12)

I suppose there's a kinda bug in through2 library usage. I'll try to figure it out and report you via PR

Error: Encrypted private key detected, but no passphrase given

When using the following code and using a passphrase protected key, I get the error:

Error: Encrypted private key detected, but no passphrase given

Code:

'use strict';
var gulp = require( 'gulp' );
var debug = require('gulp-debug');
var path = require('path');
var fs = require('fs');
var GulpSSH = require('gulp-ssh');
var expandTilde = require('expand-tilde');

var configKey = {
    host: '10.0.0.222',
    port: 22,
    username: 'myuser',
    privateKey: fs.readFileSync( expandTilde('~/.ssh/id_rsa'))
};

var gulpSSHKey = new GulpSSH({
    ignoreErrors: false,
    sshConfig: configKey
});

//Todo: Throws an error: "Error: Encrypted private key detected, but no passphrase given"
gulp.task('ssh:key', function () {
    return gulp
        .src(paths.src)
        .pipe(gulpSSHKey.dest('/cygdrive/c/Users/myuser/bla'));
});

Any ideas how to fix that?

Regards
Stefan

SFTP error or directory exists

I can see multiple errors: SFTP error or directory exists during upload. Is it a bug? The files seem to be transferred correctly, but the error messages are a bit disturbing.

Of course, it is true. The directory exists, but why is it considered as an error?

gulp-sftp : 0.1.5
ssh2: 0.5.0

Add proper error callback on connect

Currently, the gulp task ends in undefined state when connecting to a non-existing server or with wrong credentials. Instead, an error event should be fired to allow proper error handling.

gulpfile.js for testing:

var gulp = require('gulp');
var GulpSSH = require('gulp-ssh');

gulp.task('default', function (completed) {
    var gulpSSH = new GulpSSH({
        ignoreErrors: false,
        sshConfig: {
            host: 'example.com',
            port: 22,
            username: 'root',
            password: ''
        }
    });

    return gulpSSH
        .exec(['uptime'])
        .on('error', function (err) {
            completed('Completed with errors!');
        })
        .on('end', function(){
            completed();
        });
});

Can not find ssh_id file using ~/ prefix

I have a problem with this because it's not reading the key file using ~/.ssh/ssh_id.pub shortcut.
It's says the file does not exist but of course it does. I have to put the real path to work, which is /User/leo/.ssh/ssh_id.pub but does it very specific to my machine.
Any workarounds to this? I want any user with permissions to be able to deploy to the server.

dest command transfer all folders to remote?

  return gulp
    .src(paths.dist.dir + '*.html')
    .pipe(gulpSSH.dest(paths.build.htmlDir));

as result,it transfer all folders to remote, not just the html files,
for example:
[17:33:40] Finished writing '/xx/x/remote_dir/d:/project/src/xx.html

how could i only transfer the html files to remote? thx

Logging "shell" method in to the console

Hi there.

Is there's a way to log the response from "shell" method into the console simultaneously with execution?

E.g. I've been using implementation similar to below

gulpSSH
  .shell(['find /tmp'])
  .on('data', function(file) {
      file.contents.on('data', function(chunk) {
        process.stdout.write(chunk);
      });
  });

but after update to 0.4.0 it stopped working and it looks like .on('data', function(file) {}) method now returns File with the whole output.

Please advice.

shell seems doesn't callback

hi @zensh ,

I'm using gulp-ssh to exec a shell in order to unarchive files. But it seems doesn't work correctly.

As you can see, it just pause there
image

and the following is my config:
image

Could you figure out how to make it work?

See command output on terminal

I'm running a command via ssh that I really have to see the output. Is it possible to log it to the console, maybe through an data event?

gulpSSH.shell with gulp-watch

Hi buddy,
Thanks for your awesome plugin out here

I've a case where I want to copy .class files changes and then restarting tomcat6 every time there's a change

var watch = require('gulp-watch');

gulp.task('server', function () {
watch('target/classes/com/MAIN/*/.class')
.pipe(gulpSSH.dest('/var/lib/tomcat6/webapps/SOMEAPP/WEB-INF/classes/com/MAIN/'))
.pipe(gulpSSH.shell(['service tomcat6 restart'], {autoExit: false}));
});

I see that for every change the gulpSSH.dest is working just fine, but the gulpSSH.shell is working only once and not injected for the next times even when changes happens!

Can you help me with that please?

Thanks,
Kind Regards

How do I close the connection?

I don't see anywhere in the documentation how do I close the connection. When I run my gulp script it starts the ssh connection, runs the commands and hangs, making me press CTRL+C to stop the script.

"Error: Cannot parse privateKey: Unsupported key format" when using id_rsa file

Hey there. I'm having a devil of a time getting gulp-ssh to use my ssh keys; hoping to either get the problem fixed or (perhaps more likely) be educated as to whether I'm maybe doing something bone-headed… but here's the deal.

I've got these RSA ssh keys (generated using ssh-keygen with a passphrase), and I keep them in ~/.ssh, like any civilized human being might. (Perms on those files are right, just to preempt that particular question — I've been using these keys for the better part of a year to breeze around into various hosts.)

The trouble is that whenever I point gulp-ssh to my private key and attempt to access a remote host that I routinely access successfully via cli ssh, I get the following error:

Error: Cannot parse privateKey: Unsupported key format
    at Client.connect (/vagrant/node_modules/gulp-ssh/node_modules/ssh2/lib/client.js:147:13)
    at GulpSSH.connect (/vagrant/node_modules/gulp-ssh/index.js:79:15)
    at GulpSSH.exec (/vagrant/node_modules/gulp-ssh/index.js:110:8)
    # then it's my code, followed by node

I don't usually cut my code out, but here's my file:

var GulpSSH = require('gulp-ssh');

var sshConfig = {
  host: 'redacted', // redacted this for obvious reasons :)
  port: 22,
  username: 'yanni',
  privateKey: '/home/yanni/id_rsa'
};

var ssh = new GulpSSH({
  ignoreErrors: false,
  sshConfig: sshConfig
});


ssh.exec('touch ~/my-ssh-test.txt');
ssh.close();

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.