fix(release): handle explicit FTPS on port 21 via ftp:// + --ssl-reqd (auto-detect or FTPS_MODE=explicit)

This commit is contained in:
Jordan Wages 2025-08-24 04:11:18 -05:00
commit 38946e711c
2 changed files with 26 additions and 2 deletions

View file

@ -15,6 +15,11 @@ FTP_PASS=your-ftp-password
# Remote directory to upload signed artifacts (e.g., /addons/archive-org-link-grabber/)
FTP_REMOTE_DIR=/path/on/server
# FTPS mode (optional):
# explicit (FTPES on port 21) or implicit (default on port 990)
# If unset, the script auto-detects explicit when FTP_PROTOCOL=ftps and FTP_PORT=21.
# FTPS_MODE=explicit
# SFTP host verification (SFTP only; choose one)
# SFTP_KNOWN_HOSTS=/home/you/.ssh/known_hosts
# SFTP_HOST_PUBKEY_SHA256=base64sha256fingerprint

View file

@ -113,11 +113,30 @@ if (!host || !user || !pass || !remoteDir) {
if (!remoteDir.startsWith('/')) remoteDir = '/' + remoteDir;
if (remoteDir.endsWith('/')) remoteDir = remoteDir.slice(0, -1);
// Determine explicit vs implicit FTPS handling
function asBool(v) {
const s = String(v || '').toLowerCase();
return s === 'true' || s === '1' || s === 'yes' || s === 'on';
}
const ftpsMode = (process.env.FTPS_MODE || '').toLowerCase(); // 'explicit' | 'implicit' | ''
let useExplicitFtps = false;
if (protocol === 'ftps') {
if (ftpsMode === 'explicit') useExplicitFtps = true;
else if (ftpsMode === 'implicit') useExplicitFtps = false;
else if (String(port || '') === '' || String(port) === '21') useExplicitFtps = true; // default to explicit on port 21
}
// Construct base URL for FTP/SFTP upload target
const baseUrl = `${protocol}://${host}${port ? `:${port}` : ''}${remoteDir}`;
const scheme = (protocol === 'ftps' && useExplicitFtps) ? 'ftp' : protocol;
const baseUrl = `${scheme}://${host}${port ? `:${port}` : ''}${remoteDir}`;
// Prepare common curl flags
const curlBase = ['curl', '--fail', '--ftp-create-dirs'];
if (protocol === 'ftps' && useExplicitFtps) {
// Explicit FTPS (FTPES): connect plain on port 21 and then upgrade to TLS
// Modern curl prefers --ssl-reqd; keep compatibility with older --ftp-ssl-reqd if available
curlBase.push('--ssl-reqd');
}
// Detect curl option support dynamically to stay compatible with older curl versions
function curlSupports(opt) {
try {
@ -211,7 +230,7 @@ function ensureUpdatesJson() {
ensureUpdatesJson();
console.log(`Uploading ${files.length} file(s) from ${artifactsDir} to ${protocol}://${host}${port ? `:${port}` : ''}${remoteDir}/`);
console.log(`Uploading ${files.length} file(s) from ${artifactsDir} to ${scheme}://${host}${port ? `:${port}` : ''}${remoteDir}/`);
for (const file of files) {
const localPath = path.join(artifactsDir, file);