node.js的FTP客户端模块:node-ftp

jopen 10年前

node-ftp是一个node.js的FTP客户端模块,提供了一个用于与FTP服务器进行通信的异步接口。

示例

  • 获取当前的(远程)工作目录的目录列表:
      var Client = require('ftp');      var c = new Client();    c.on('ready', function() {      c.list(function(err, list) {        if (err) throw err;        console.dir(list);        c.end();      });    });    // connect to localhost:21 as anonymous    c.connect();
  • 下载远程文件“foo.txt”,并将其保存到本地文件系统:
      var Client = require('ftp');    var fs = require('fs');      var c = new Client();    c.on('ready', function() {      c.get('foo.txt', function(err, stream) {        if (err) throw err;        stream.once('close', function() { c.end(); });        stream.pipe(fs.createWriteStream('foo.local-copy.txt'));      });    });    // connect to localhost:21 as anonymous    c.connect();
  • 上传本地文件“foo.txt'到服务器:
      var Client = require('ftp');    var fs = require('fs');      var c = new Client();    c.on('ready', function() {      c.put('foo.txt', 'foo.remote-copy.txt', function(err) {        if (err) throw err;        c.end();      });    });    // connect to localhost:21 as anonymous    c.connect();

项目主页:http://www.open-open.com/lib/view/home/1408006289661