Fix FTP connection timeout: add 15s timeout and accept self-signed certs

The FTP client had no timeout, causing Vercel function timeouts on
connection issues. Added a 15-second timeout to both pollFtp and
testFtpConnection. Also added secureOptions.rejectUnauthorized=false
to prevent TLS failures with self-signed or non-standard certificates.

Made-with: Cursor
This commit is contained in:
Randall Stillwell 2026-04-17 14:46:16 -05:00
parent 58d8d99625
commit bc5ad6dbdb

View file

@ -38,7 +38,7 @@ export async function pollFtp(): Promise<{ processed: number; skipped: number; e
return { processed: 0, skipped: 0, error: "FTP not configured" };
}
const client = new Client();
const client = new Client(15_000);
let processed = 0;
let skipped = 0;
@ -49,6 +49,7 @@ export async function pollFtp(): Promise<{ processed: number; skipped: number; e
user: settings.ftpUser,
password: settings.ftpPass,
secure: settings.ftpTls,
secureOptions: { rejectUnauthorized: false },
});
log(`Connected to ${settings.ftpHost}:${settings.ftpPort}`);
@ -126,7 +127,7 @@ export async function testFtpConnection(config: {
tls: boolean;
incomingDir: string;
}): Promise<{ ok: boolean; files?: number; error?: string }> {
const client = new Client();
const client = new Client(15_000);
try {
await client.access({
host: config.host,
@ -134,6 +135,7 @@ export async function testFtpConnection(config: {
user: config.user,
password: config.pass,
secure: config.tls,
secureOptions: { rejectUnauthorized: false },
});
const files = await client.list(config.incomingDir);