1

I decided to use vinyl-ftp for my deployment process in gulp. One thing I would like to do is to have a separate file with my ftp credentials:

  1. host

  2. user

  3. password

    and put that file in my .gitignore. And then I want those credentials in that file be read by my connection variable in my gulp file. My deploy code is the following:

    gulp.task( 'deploy', function () {
    var conn = ftp.create( {
    host:     'yourdomain.com',
    user:     'ftpusername',
    password: 'ftpuserpassword',
    parallel: 10,
    log:      gutil.log
    } );
    
    var globs = [
    'dist/**'
    ];
    
    return gulp.src( globs, { base: './dist/', buffer: false } )
    .pipe( conn.newer( 'yourdomain.com' ) )
    .pipe( conn.dest( 'yourdomain.com' ) );
    
    } );//end deploy
    

So I want the values of the variables yourdomain.com for the host, ftpusername for user and ftpuserpassword for password be read in from a separate file so my credentials show up when I do git push. How do I accomplish this?

Thanks

Community
  • 1
  • 1
user2371684
  • 1,475
  • 5
  • 20
  • 45
  • I did try to create a ftp.json file with my host, user and password credentials and added that to my .gitigonre file and saved it on the root of my folder, same locations as my gulpfile.js, and in my gulpfile.js I added the declaration: var ftp_cred = require('ftp.json') and when I run gulp deploy, I get the error: Error: Cannot find module 'ftp.json' – user2371684 Jan 12 '18 at 21:02
  • And did you export the ftp.json file too, like exports.ftp= ftp; ? See https://blueprintinteractive.com/blog/how-sync-local-and-server-development-gulp for a good article on what you are trying to do. – Mark Feb 22 '18 at 06:09
  • thanks, I followed the excellent article you suggested, but it freezes after going through the config file with the ftp credentials. It says CONN twice and is stuck. The login credentials have been checked out manually on filezilla and there they are connecting. – user2371684 Feb 26 '18 at 17:27

1 Answers1

1

You can pass them as run args:

var 
    gulp           = require('gulp'),
    args           = require('yargs').argv;
const distDir = "./dist";
gulp.task('deploy', function() {
    var conn = ftp.create({
        host:      args.host,
        user:      args.user,
        password:  args.password,
        parallel:  10,
        log: flog // .log
    });

    var globs = [
    distDir + '/**',
    distDir + '/.htaccess',
    ];
    return gulp.src(globs, {buffer: false})  
    .pipe(conn.dest(args.remotedir));

});

Then call it from command line or put the line in a batch file: npm run gulp deploy -- --host=hostname --user=username --password=password --remotedir=/path/to/folder/on/server. Use gulp instead of npm run gulp if gulp is installed global.

This is a good practice to pass credentials trough args at a program start.

Dr.eel
  • 1,837
  • 3
  • 18
  • 28