同时使用 gulp-prompt 和 gulp-ftp

Using gulp-prompt and gulp-ftp together?

本文关键字:gulp-ftp gulp-prompt      更新时间:2023-09-26

我有一个 ftp 服务器,我曾经使用 Grunt 任务部署到它。 我现在正在使用Gulp。

我很快就找到了gulp-ftp,除了它将ftp密码存储在gulpfile中......所以我然后找到了gulp-prompt,它将允许脚本每次都提示。好。

但是,我一起使用它们时遇到问题。 我不确定如何以及在何处将ftp任务集成到密码提示中:

gulp.task('deploy', function () {
 return gulp.src('build/*')
  .pipe(prompt.prompt({
   type: 'password',
   name: 'pass',
   message: 'Please enter your password'
 }, function(res){
//value is in res.pass
ftp({
  host: 'ftp.mysite.com',
  user: 'mrwonderful',
  pass: res.pass
 });
}))

这显然是错误的,因为它抛出了一大堆难以理解的错误。

我以前没有使用gulp-prompt。您现在 ftp 不是安全的连接方式,并且您的密码未加密?但我使工作 gulp-ftp 和 gulp 提示:

gulp.task('deploy', function () {
    return gulp.src('/')//it may be anything
    .pipe(prompt.prompt({
    type: 'password',
    name: 'pass',
    message: 'Please enter your password'
    }, function(res){
        gulp.src(['archive.zip'],{ base: './' })//now you have to target what you want to send
        .pipe(ftp({
            host: 'yourhost',
            user: 'youruser',
            pass: res.pass
        }));
    }));
});

我建议您使用 SCP 或 SSH 发送。我在上传之前压缩项目,然后通过 ssh 解压缩它。