# 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',
  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: true,
  // use sftp or ftp
  sftp: true,
};

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

# 3. 参考

本章目录