/** * FTP 代理服务测试示例 * 演示如何使用 FTP 代理控制器提供文件直链服务 */ import Fastify from 'fastify'; import ftpProxyController from '../controllers/ftp-proxy.js'; // 创建 Fastify 实例 const fastify = Fastify({ logger: { level: 'info' } }); // 添加根路径处理 fastify.get('/', async (request, reply) => { return reply.type('text/html').send(`
这是一个 FTP 文件代理服务,提供 HTTP 直链访问 FTP 服务器上的文件。
json/ftp.json 文件,或在请求中提供 FTP 配置参数。
curl http://localhost:3000/ftp/health
curl http://localhost:3000/ftp/status
path - 目录路径(可选,默认为 /)config - FTP 配置(可选,JSON 格式)curl "http://localhost:3000/ftp/list?path=/"curl "http://localhost:3000/ftp/list?path=/uploads"
path - 文件路径(必需)config - FTP 配置(可选,JSON 格式)curl "http://localhost:3000/ftp/info?path=/readme.txt"
path - 文件路径(必需)config - FTP 配置(可选,JSON 格式)curl "http://localhost:3000/ftp/file?path=/readme.txt"curl "http://localhost:3000/ftp/file?path=/images/photo.jpg" -o photo.jpgcurl -H "Range: bytes=0-1023" "http://localhost:3000/ftp/file?path=/large-file.zip"
{
"host": "192.168.31.10",
"port": 2121,
"username": "anonymous",
"password": "anonymous@example.com",
"secure": false,
"pasv": true
}
示例:curl -X POST -H "Content-Type: application/json" -d '{"host":"192.168.31.10","port":2121}' http://localhost:3000/ftp/config
curl -X DELETE http://localhost:3000/ftp/cache
FTP 配置文件位置:json/ftp.json
{
"host": "192.168.31.10",
"port": 2121,
"username": "anonymous",
"password": "anonymous@example.com",
"secure": false,
"pasv": true,
"timeout": 30000,
"verbose": false
}
json/ftp.json 文件node ftp-proxy-example.jscurl http://localhost:3000/ftp/healthcurl "http://localhost:3000/ftp/list?path=/"curl "http://localhost:3000/ftp/file?path=/your-file.txt"