beckham79 发表于 2015-11-6 09:42:51

GruntJs之FTP上传文件

  因为项目需要,又试了一下Grunt的FTP插件:grunt-ftpscript。以下步骤是基于上一篇博文的配置环境的:http://blog.iyunv.com/puncha/article/details/10442147。
  


  (一)安装
  


[*]C:\Grunt>npm install grunt-ftpscript --save-dev
[*]C:\Grunt>npm install matchdep --save

装matchdep是为了能够通过一句命令,加载所有的Grunt插件,在下面的代码里面就能看到。




(二)代码:
  这里我没有直接执行task,而是随后通过命令行执行的。
  


Gruntfile.js:


module.exports = function (grunt) {
grunt.initConfig({
ftpscript: {
main: {
options: {
host: 'shacng109wqrh',
port: 21,
passive: true
},
files: [
{ expand: true, cwd: 'filesToCopy', src: ['*'], dest: '/filesCopied/' }
]
}
},
});
require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks);
};

.ftppass: (因为我没设FTP密码,所以不能写password这个属性,不然会出现笨等待)
  


{
"shacng109wqrh" : {
"username": "cer"
}
}
  
(三)运行:
C:\Grunt>grunt ftpscript:main


提示成功:


Running "ftpscript:main" (ftpscript) task
Connected to SHACNG109WQRH.ads.autodesk.com.
220-FileZilla Server version 0.9.41 beta
220-written by Tim Kosse (Tim.Kosse@gmx.de)
>> 220 Please visit http://sourceforge.net/projects/filezilla/
Interactive mode Off .
Invalid command.
>> 257 "/filesCopied" created successfully
>> 226 Transfer OK
ftp: 382 bytes sent in Seconds Kbytes/sec.
0.00382000.00221 Goodbye
Done, without errors.
  
就这么简单~~~





  












版权声明:本文为博主原创文章,未经博主允许不得转载。
页: [1]
查看完整版本: GruntJs之FTP上传文件