M
M
M1Anderson2015-08-11 19:53:29
FTP
M1Anderson, 2015-08-11 19:53:29

Gulp deploy ftp without src directory?

Hello.
There is a need to upload the project to ftp via gulp. The problem is that it sends the entire src directory and on the server you have to transfer files from the directory to another, which is not very good.
Those. projects/test/ src is created , but I would like the files to be immediately sent to projects/test, i.e. no src at all.
Task:

var gutil = require( 'gulp-util' );
var ftp = require( 'vinyl-ftp' );

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

    var conn = ftp.create( {
        host:     'hydrogen',
        user:     'hosting',
        password: 'test',
        parallel: 10,
        log:      gutil.log
    } );

    var globs = [
        'src/**',
        'css/**',
        'js/**',
        'fonts/**',
        'index.html'
    ];

    // using base = '.' will transfer everything to /public_html correctly
    // turn off buffering in gulp.src for best performance

    return gulp.src( globs, { base: '.', buffer: false } )
        .pipe( conn.newer( '/projects/test' ) ) // only upload newer files
        .pipe( conn.dest( '/projects/test' ) );

} );

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexey Sosnovsky, 2015-10-08
@sosnovskyas

how about in the variable that you use to determine which files you send to the server write and write an exception,
for example
, or how is it in your project, in general, the correct path that you want to exclude and in front of it is an exclamation mark (!)

M
mivo, 2016-12-05
@mivo

You just need to change Base

gulp.task('deploy', function () {
 
  var conn = ftp.create( {
    host:     'host.ru',
    user:     'user',
    password: 'password',
    parallel: 10,
    log:      gutil.log
  });

  const path = '/domains/host.ru/public_html';

  var globs = [
    'dist/**/*.*'
  ];

  conn.rmdir(path, function(e){
    if (e === undefined) {
      // using base = '.' will transfer everything to /public_html correctly 
      // turn off buffering in gulp.src for best performance 
      return gulp.src(globs, {base: 'dist', buffer: false})
        // .pipe(conn.newer(path)) // only upload newer files 
        .pipe(conn.dest(path));
    }
    return console.log(e);
  });
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question