npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

vite-plugin-deploy-ftp

v1.1.2

Published

将dist目录下的文件上传到ftp服务器

Readme

vite-plugin-deploy-ftp

将 dist 目录上传到 FTP 服务器,支持单个或多个 FTP 服务器配置

介绍

vite-plugin-deploy-ftp 是一个 Vite 插件,用于将打包后的文件上传到 FTP 服务器。插件支持:

  • 单个 FTP 服务器配置
  • 多个 FTP 服务器配置(可多选上传目标)
  • 自动备份远程文件
  • 连接重试机制
  • 选择性文件备份

安装

pnpm add vite-plugin-deploy-ftp -D

使用

单个 FTP 配置

// vite.config.ts
import vitePluginDeployFtp from 'vite-plugin-deploy-ftp'

export default {
  plugins: [
    vitePluginDeployFtp({
      open: true,
      host: 'ftp.example.com',
      port: 21,
      user: 'username',
      password: 'password',
      uploadPath: '/public_html',
      alias: 'https://example.com',
      singleBack: false,
      singleBackFiles: ['index.html'],
      maxRetries: 3,
      retryDelay: 1000,
    }),
  ],
}

多个 FTP 配置

// vite.config.ts
import vitePluginDeployFtp from 'vite-plugin-deploy-ftp'

export default {
  plugins: [
    vitePluginDeployFtp({
      open: true,
      uploadPath: '/public_html',
      singleBack: false,
      singleBackFiles: ['index.html'],
      maxRetries: 3,
      retryDelay: 1000,
      ftps: [
        {
          name: '生产环境',
          host: 'ftp.production.com',
          port: 21,
          user: 'prod_user',
          password: 'prod_password',
          alias: 'https://production.com',
        },
        {
          name: '测试环境',
          host: 'ftp.test.com',
          port: 21,
          user: 'test_user',
          password: 'test_password',
          alias: 'https://test.com',
        },
        {
          name: '开发环境',
          host: 'ftp.dev.com',
          port: 21,
          user: 'dev_user',
          password: 'dev_password',
          alias: 'https://dev.com',
        },
      ],
    }),
  ],
}

配置参数

通用参数

| 参数 | 类型 | 默认值 | 说明 | | ----------------- | ---------- | ---------------- | -------------------------------- | | open | boolean | true | 是否启用插件 | | uploadPath | string | - | FTP 服务器上的上传路径 | | singleBack | boolean | false | 是否使用单文件备份模式 | | singleBackFiles | string[] | ['index.html'] | 单文件备份模式下要备份的文件列表 | | maxRetries | number | 3 | 连接失败时的最大重试次数 | | retryDelay | number | 1000 | 重试延迟时间(毫秒) |

单个 FTP 配置参数

| 参数 | 类型 | 默认值 | 说明 | | ---------- | -------- | ------ | -------------------------- | | host | string | - | FTP 服务器地址 | | port | number | 21 | FTP 服务器端口 | | user | string | - | FTP 用户名 | | password | string | - | FTP 密码 | | alias | string | '' | 网站别名,用于生成完整 URL |

多个 FTP 配置参数

| 参数 | 类型 | 说明 | | ------ | ------------- | ------------------ | | ftps | FtpConfig[] | FTP 服务器配置数组 |

FtpConfig 对象

| 参数 | 类型 | 默认值 | 说明 | | ---------- | -------- | ------ | ---------------------------------- | | name | string | - | FTP 服务器名称(用于选择界面显示) | | host | string | - | FTP 服务器地址 | | port | number | 21 | FTP 服务器端口 | | user | string | - | FTP 用户名 | | password | string | - | FTP 密码 | | alias | string | '' | 网站别名,用于生成完整 URL |

功能特性

多服务器选择

当使用多个 FTP 配置时,插件会显示一个多选界面,让您选择要上传到哪些服务器:

? 选择要上传的FTP服务器(可多选)
❯ ◯ 生产环境
  ◯ 测试环境
  ◯ 开发环境

备份功能

插件提供两种备份模式:

  1. 完整备份: 将远程目录下的所有文件打包备份
  2. 选择性备份: 只备份指定的文件(通过 singleBackFiles 配置)

连接重试

当 FTP 连接失败时,插件会自动重试,您可以通过 maxRetriesretryDelay 参数控制重试行为。

环境变量示例

建议将敏感信息(如用户名和密码)放在环境变量中:

# .env
VITE_FTP_HOST=ftp.example.com
VITE_FTP_PORT=21
VITE_FTP_USER=username
VITE_FTP_PASSWORD=password
VITE_FTP_PATH=/public_html
VITE_FTP_ALIAS=https://example.com
// vite.config.ts
export default {
  plugins: [
    vitePluginDeployFtp({
      host: process.env.VITE_FTP_HOST,
      port: +(process.env.VITE_FTP_PORT || 21),
      user: process.env.VITE_FTP_USER,
      password: process.env.VITE_FTP_PASSWORD,
      uploadPath: process.env.VITE_FTP_PATH,
      alias: process.env.VITE_FTP_ALIAS,
    }),
  ],
}