Automate outbound uploads with cron and shell tools so each ERP batch lands in sent_inbox without manual clicks.
Design principles
Throughput and limits
Only `.json` and `.xlsx` files in
sent_inboxare processed (*.partand other extensions are ignored).Your organization has a maximum concurrent file processing setting (configured by ArdentaxIT). The platform default is 2 files at a time unless your account is configured higher. Extra files in
sent_inboxwait in place until a worker slot frees up (oldest pickup first — FIFO queue); they are not dropped. There is no documented maximum queue depth — stagger cron if you routinely land large backlogs. Avoid landing thousands of tiny files in the same minute—batch into fewer XLSX files or stagger cron uploads.JSON uploads are one document per file; multi-document batches belong in XLSX when possible.
Atomic upload pattern
Write
/data/export/inv-20260326-001.json.partlocally.Upload to
sent_inbox/inv-20260326-001.json.partvia SFTP.Rename on server to
sent_inbox/inv-20260326-001.json(SFTPrename).
Some clients upload to a staging folder outside sent_inbox, then rename into sent_inbox in one session.
Batch file with OpenSSH `sftp`
#!/usr/bin/env bash
set -euo pipefail
HOST="<sftp-host>"
PORT="<port>"
USER="<username>"
LOCAL_FILE="/data/export/inv-$(date +%Y%m%d-%H%M%S).json"
REMOTE_STEM="$(basename "$LOCAL_FILE")"
# ERP export command here — must finish before upload
erp_export_sales_batch > "$LOCAL_FILE"
BATCH=$(mktemp)
cat > "$BATCH" <<EOF
cd sent_inbox
put ${LOCAL_FILE} ${REMOTE_STEM}.part
rename ${REMOTE_STEM}.part ${REMOTE_STEM}
bye
EOF
sftp -P "$PORT" -b "$BATCH" "${USER}@${HOST}"
rm -f "$BATCH"
echo "uploaded ${REMOTE_STEM}"Append the stem to a local ledger:
echo "$REMOTE_STEM" >> /var/lib/sftp-integration/uploaded.stems`lftp` mirror (optional)
Useful when multiple files land in a spool directory:
#!/usr/bin/env bash
set -euo pipefail
lftp -u "<username>,<password>" sftp://<sftp-host>:<port> <<EOF
set sftp:connect-program "ssh -a -x"
cd sent_inbox
mput /data/spool/*.json
bye
EOFPrefer rename-after-upload per file when the ERP drops files incrementally.
Cron schedule
# Every hour at minute 5
5 * * * * /opt/sftp/upload-sales-sftp.sh >> /var/log/sftp-upload.log 2>&1Stagger large batches to avoid thousands of simultaneous files with identical timestamps—use monotonic batch ids from the ERP.
Retry and idempotency
Do not delete a failed upload and re-push the same remote name expecting a replay.
Fix the payload, generate a new filename, upload again.
If upload fails mid-transfer, remove the partial
.partobject before retrying.
Pair with status polling
Upload automation should trigger or schedule a separate job that polls sent_archive/*_index.* (see Poll submitted status).
