# FTP 自动部署- ftp-deploy

# 1. 介绍

通过 ftp-deploy 将 dist 目录里的内容上传到服务器

# 2. 使用

安装:

npm i -D ftp-deploy

# "ftp-deploy": "^2.4.7",

使用:

// proj/builds/deploy.js

const FtpDeploy = require('ftp-deploy');
const path = require('path');

const ftpDeploy = new FtpDeploy();

const config = {
  host: '1.2.3.4',
  port: 22,
  user: 'wuqinfei',
  password: '123456',
  localRoot: path.resolve(__dirname, '../dist'),
  remoteRoot: '/www',
  /*

    注意: 
      匹配路径模式的文件会原样拷贝过去(包括文件夹)
      这些路径模式都是相对路径,不是从根路径开始的
      也就是说,要排除掉 node_modules

    dir/*  : dir 目录下的所有子文件,不包括子目录
    dir/** : dir 目录下的文件及文件夹
    1.txt  : 
   */
  include: [
    '*', 
    '**/*',
  ],
  // e.g. exclude sourcemaps, and ALL files in node_modules (including dot files)
  exclude: [],
  // delete ALL existing files at destination before uploading, if true
  deleteRemote: false,
  // Passive mode is forced (EPSV command is not sent)
  forcePasv: false,

  // use sftp or ftp
  sftp: false,
};

ftpDeploy
  .deploy(config)
  .then((res) => console.log('finished:', res))
  .catch((err) => console.log(err));

# 3. 参考

本章目录