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:
parent
58d8d99625
commit
bc5ad6dbdb
1 changed files with 4 additions and 2 deletions
|
|
@ -38,7 +38,7 @@ export async function pollFtp(): Promise<{ processed: number; skipped: number; e
|
||||||
return { processed: 0, skipped: 0, error: "FTP not configured" };
|
return { processed: 0, skipped: 0, error: "FTP not configured" };
|
||||||
}
|
}
|
||||||
|
|
||||||
const client = new Client();
|
const client = new Client(15_000);
|
||||||
let processed = 0;
|
let processed = 0;
|
||||||
let skipped = 0;
|
let skipped = 0;
|
||||||
|
|
||||||
|
|
@ -49,6 +49,7 @@ export async function pollFtp(): Promise<{ processed: number; skipped: number; e
|
||||||
user: settings.ftpUser,
|
user: settings.ftpUser,
|
||||||
password: settings.ftpPass,
|
password: settings.ftpPass,
|
||||||
secure: settings.ftpTls,
|
secure: settings.ftpTls,
|
||||||
|
secureOptions: { rejectUnauthorized: false },
|
||||||
});
|
});
|
||||||
|
|
||||||
log(`Connected to ${settings.ftpHost}:${settings.ftpPort}`);
|
log(`Connected to ${settings.ftpHost}:${settings.ftpPort}`);
|
||||||
|
|
@ -126,7 +127,7 @@ export async function testFtpConnection(config: {
|
||||||
tls: boolean;
|
tls: boolean;
|
||||||
incomingDir: string;
|
incomingDir: string;
|
||||||
}): Promise<{ ok: boolean; files?: number; error?: string }> {
|
}): Promise<{ ok: boolean; files?: number; error?: string }> {
|
||||||
const client = new Client();
|
const client = new Client(15_000);
|
||||||
try {
|
try {
|
||||||
await client.access({
|
await client.access({
|
||||||
host: config.host,
|
host: config.host,
|
||||||
|
|
@ -134,6 +135,7 @@ export async function testFtpConnection(config: {
|
||||||
user: config.user,
|
user: config.user,
|
||||||
password: config.pass,
|
password: config.pass,
|
||||||
secure: config.tls,
|
secure: config.tls,
|
||||||
|
secureOptions: { rejectUnauthorized: false },
|
||||||
});
|
});
|
||||||
|
|
||||||
const files = await client.list(config.incomingDir);
|
const files = await client.list(config.incomingDir);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue