PunCha

导航

GruntJs之FTP上传文件

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


(一)安装

  1. C:\Grunt>npm install grunt-ftpscript --save-dev
  2. 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.

就这么简单~~~







posted on 2013-08-28 15:43  PunCha  阅读(273)  评论(0编辑  收藏  举报