Giter Club home page Giter Club logo

grunt-scp's Introduction

grunt-scp

Copy files to remote server

Getting Started

This plugin requires Grunt >=0.4.5

If you haven't used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:

npm install grunt-scp

One the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:

grunt.loadNpmTasks('grunt-scp');

The "scp" task

Overview

In your project's Gruntfile, add a section named scp to the data object passed into grunt.initConfig().

grunt.initConfig({
  pkg: grunt.file.readJSON('package.json'),

  scp: {
    options: {
        host: 'localhost',
        username: 'username',
        password: 'password'
    },
    your_target: {
        files: [{
            cwd: 'directory',
            src: '**/*',
            filter: 'isFile',
            // path on the server
            dest: '/home/username/static/<%= pkg.name %>/<%= pkg.version %>'
        }]
    },
  },
})

Options

options.host

Type: String Default value: localhost

A string value that is the host of the server.

options.port

Type: Number Default value: 22

The ssh port of the server.

options.username

Type: String

The username used to log into the server.

options.password

Type: String

The password of the above user on the remote server.

options.log

Type: Function

More Options

  • host
  • port
  • hostHash
  • hostVerifier
  • username
  • password
  • agent
  • privateKey
  • passphrase
  • publicKey

Read more: https://github.com/mscdex/ssh2#connection-methods

Changelog

2018-09-22 0.1.11

Add support for [email protected]

2013-11-14 0.1.6

Update dependency of scp2.

2013-06-04 0.1.5

Update dependency of scp2. Add transfer log.

2013-06-01 0.1.4

Fix on default options.

2013-04-09 0.1.3

Add a config file to make things easier.

2013-04-09 0.1.2

Add options.log.

2013-03-29 0.1.1

Add client.on('error') handler.

2013-03-08 0.1.0

First version.

grunt-scp's People

Contributors

2silver avatar dkurucz avatar geedew avatar jfgodoy avatar lepture avatar morrissinger avatar nickbabcock avatar popomore avatar vaenow avatar

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

Watchers

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

grunt-scp's Issues

Use OSX ~/.ssh/config

I want to be able to use this with already authorised keys.

I can SSH to my server just fine but not 100% sure how to use this without specifying either the password or the privateKey in the config. Is there a way to get it to use OSX's default ssh config?

Fatal error: handle is not a Buffer while doing scp

my gruntfile.js is below

  secret: grunt.file.readJSON('environment.json'),
  scp: {
       test:{
         options: {
           host: '<%= secret.server1.host %>',
           username: '<%= secret.server1.username %>',
           privateKey: '<%= grunt.file.read(secret.server1.privateKey) %>',
           showProgress: true
          // tryKeyboard: true
         }, 
         files: [{
             cwd: './dist',
             src: '**/*',
             filter: 'isFile',
             dest: '/path/to/folder/project.test'
         }]  
       },
       prod: {
         options: {
           host: '<%= secret.server2.host %>',
           username: '<%= secret.server2.username %>',
           privateKey: '<%= grunt.file.read(secret.server2.privateKey) %>',
           tryKeyboard:true
         },
         files: [{
             cwd: './dist',
             src:'**/*',
             dest:'/srv/www/vhosts/project'
         }]
       } 
   } `

when i try to deploy to test
i get following error

               [31mFatal error: handle is not a Buffer��[39m
              14:28:21 
              14:28:21 
              14:28:21 Execution Time (2014-11-12 01:25:31 UTC)

please help, Thanks

Login with KeyboardInteractive

Are there any plans so support keyboard interactive login?

Currently I can add tryKeyboard: true to the options but whenever I do so the script hangs.

NPM doesn't have latest code

I am wanting to use the latest code which has keyboard interactivity when you put password as true. It doesn't seem that the NPM is pulling the latest code. As I am not as familiar with NPM and Plugin interaction is there a missing step that would make sure NPM pulls the latest code?

Update to scp2 dependency

npm audit reports using old scp2 module < 3.0.2 causing "high" risk Regular Expression Denial of Service warnings.

Fatal error: handle is not a Buffer

升级后,没改动任何代码,报错。

write path/to/foo.js/foo.js

只存在 path/to/foo.js 这个文件,现在路径莫名重复了文件名

Process Function doesn't trigger

I would like to call a function before copying my files.
With grunt, you can normally do :

copy: {
  myTask: {
    options: {                
      process: function (content, srcpath) {
        return content;
      }
    },
    files: [...]
  }
}

I would like to do the same using scp, unfortunately it doesn't trigger the function. Any solution or alternative ?

Bad destination file if expand:true

There is a problem with file resolvings in upload method if you set standard grunt's files' config
expand: true. Files are then uploaded to path eg.

mkdir /kernel/services/console.js
mkdir /kernel/services/console.js/services
write /kernel/services/console.js/services/console.js

for config

{
expand: true,
filter: 'isFile',
cwd: 'build/kernel',
src: '**/*',
dest: 'kernel/'
}

And filter filter: 'isFile' is needed to be configured, which is not clearly said why to do it.

Certificate login [enhancement]

It would be awesome to have support for SSH certificate auth. I'm interested in using Grunt to perform some configuration actions on the OpenShift PaaS. But it only allows certificate login.

My DSA key, without passphrase, isn't working.

scp: {
  options: {
    host: 'host',
    port: 22,
    username: 'root',
    privateKey: grunt.file.read('/Users/nblasgen/.ssh/id_dsa')
  }, ...
}

If I run the task without a passphrase, I get:

Fatal error: Encrypted private key detected, but no passphrase given

If I change the passphrase to null, same error. If I change it to "" (empty string) I get:

Fatal error: Unable to parse private key while generating public key (expected sequence)

Any ideas? I've googled quite a bit.

Any chance of supporting a newer version of Grunt?

This module is incredibly useful to me, and I don't want to find an alternative. I'm happy to fork the code myself and help out, if someone can tell me what I need to do.

[email protected] is the latest version of Grunt that can be used with this module. That version of Grunt has out-of-date dependencies ([email protected]), which will be fully deprecated on node releases >= v7.0. Is there a reason why this package has a locked-in peer dependency? Any chance of it being updated for newer versions of Grunt?

install error

Hi,

I meet some problems when install the package with npm. The error information as following.


npm http GET https://registry.npmjs.org/grunt-scp
npm http GET https://registry.npmjs.org/grunt-scp
npm http GET https://registry.npmjs.org/grunt-scp
npm ERR! Error: UNABLE_TO_VERIFY_LEAF_SIGNATURE
npm ERR!     at SecurePair.<anonymous> (tls.js:1370:32)
npm ERR!     at SecurePair.EventEmitter.emit (events.js:92:17)
npm ERR!     at SecurePair.maybeInitFinished (tls.js:982:10)
npm ERR!     at CleartextStream.read [as _read] (tls.js:469:13)
npm ERR!     at CleartextStream.Readable.read (_stream_readable.js:320:10)
npm ERR!     at EncryptedStream.write [as _write] (tls.js:366:25)
npm ERR!     at doWrite (_stream_writable.js:226:10)
npm ERR!     at writeOrBuffer (_stream_writable.js:216:5)
npm ERR!     at EncryptedStream.Writable.write (_stream_writable.js:183:11)
npm ERR!     at write (_stream_readable.js:582:24)


Be able to configure feedback about sftp transfer

When transfering big files, it's hard (if not impossible) to know if a transfer has stalled or is working. Being able to enable a feedback on the file transfer would be great.

Running "scp:instance_1" (scp) task
.ssh connect 33.33.33.60
write /var/deploy/my-app.zip
ssh close 33.33.33.60

Done, without errors.

could be

Running "scp:instance_1" (scp) task
.ssh connect 33.33.33.60
write /var/deploy/my-app.zip.................................
ssh close 33.33.33.60

Done, without errors.

And on the config side of things:

 grunt.initConfig( {
    scp: {
        options: {
            host: '33.33.33.60',
            username: 'deploy',
            privateKey: grunt.file.read('~/.ssh/id_dsa'),
            feedback: true,
        },
        instance_1: {
            files: [{
                cwd: './',
                src: 'my-app.zip',
                filter: 'isFile',
                // path on the server
                dest: '/var/www/'
            }]
        },
    },      
  })

I'm not sure if that's still something we're not able to do due to some limitation on https://github.com/mscdex/ssh2, if someone has a better understanding of the underlying api's please comment (I wouldn't be surprised if we can already enable it through some other option).

Read private key

Having a private key hardwired into a gruntfile seems to me to be a really bad idea. I think you need an option that specifies a key file to read.

Configuring without ``cwd`` causes a path.resolve warning

Using grunt-scp without a cwd option in the files configuration produces the following warning:

$ grunt -vvv
...
Verifying property scp.upload exists in config...OK
Files: ... -> /opt/data
Options: host="example.org", username="root", password="password"
Warning: Arguments to path.resolve must be strings Use --force to continue.

Aborted due to warnings.

I had thought that doing the following with src: 'build/*' should be okay:

        scp: {
            options: {
                host: 'example.org',
                username: 'root',
                password: 'password'
            },
            upload: {
                files: [
                    {src: 'build/*', dest: '/opt/data'}
                ]
            }
        }

Seems the issue is https://github.com/spmjs/grunt-scp/blob/master/tasks/scp.js#L81, where fileObj.cwd and fileObj.orig.cwd are both undefined.

Using grunt 0.4.5, grunt-scp 0.1.7, npm 1.4.21 and Node v0.10.25.

Must I use the 'cwd'?

When I missed the cwd option, I got a error:

Arguments to path.resolve must be strings Use

And after I add the cwd option, the error is gone.

before:

   scp: {
        options: {
        },
        beta: {
            files: [{
                src: 'newer/**',
                filter: 'isFile',
                dest: '/home/cdn/test'
            }]
        },
    },

after:

   scp: {
        options: {
        },
        beta: {
            files: [{
                cwd:'newer',
                src: '**',
                filter: 'isFile',
                dest: '/home/cdn/test'
            }]
        },
    },

Registering multiple tasks

I want to deploy the same file to two different locations: Dev and UAT. So I define a task as such:

scp : {
      dev: {
        options : {
          host : 'myip',
          username : 'username',
          password : 'password'
        },
        your_target: {
          files: [{
              cwd: '<% yeoman.exports %>',
              src: 'exports/my.war',
              //filter: 'isFile',
              // path on the server
              dest: '/full/path/to/location/'
          }]
        } 
      }
    }

Which doesn't work when I call scp:dev

When I remote the dev object and call scp it works fine.

Is this an issue or am I using incorrectly?

Configure File permissions

I'd like the ability to configure the file permissions when I am SCP. Is this something that can be enhanced here or is there something else that needs to be done prior?

multiple setting doesn't work

it's doesn't work.

config.scp = {
     "dev" : { "options" : {
                "host" : "aa",
                "username" : "set",
                "password" : "set"
            },
            "upload" : {
                "files" : [{
                    "cwd" : "./",
                    "src" : "set.zip",
                    "filter" : "isFile",
                    "dest" : "./"
                }]
            },
  "live" : {}
}

grunt scp:dev:upload;

is there anything errors?

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.