Remote Backup Handling in DirectAdmin: FTP Transfers, Debugging, Custom ftp_upload.php, and Alternative Upload Methods

DirectAdmin currently supports remote backups via FTP/FTPS. This article explains how to configure remote FTP backups, manually test the ftp_upload.php script, understand all available environment variables, customize the upload process, convert ftp_upload.php to use curl or ncftpput, and troubleshoot common issues. It also covers how to override the default PHP-based uploader for advanced workflows.

FTP TransfersRemote BackupAlternative Upload Methods

~4 min read • Updated Feb 27, 2026

1. Remote Backup Options in DirectAdmin


As of now, DirectAdmin supports only one built‑in method for remote backups: transferring backup files to a remote FTP server. This is configured through:


Admin Level → Admin Backup/Transfer

Both FTP and FTPS are supported.


2. Manually Testing ftp_upload.php


If you need to debug FTP upload issues, you can manually run the ftp_upload.php script with environment variables.


2.1 Example Test Command


cd /usr/local/directadmin/scripts
ftp_port=21 \
ftp_local_file=/path/to/a/file.txt \
ftp_ip=1.2.3.4 \
ftp_username=fred \
ftp_password_esc_double_quote=fredspass \
ftp_path=/remote/path \
ftp_secure=ftps \
./ftp_upload.php

This will display any errors directly in the terminal. You should also check logs on the remote FTP server or run it in debug mode.


3. Environment Variables Available to ftp_upload.php


When customizing ftp_upload.php, it’s important to know which variables DirectAdmin passes to it. Below is an example output for a cron‑based FTP backup with ID=1:


action=backup
append_to_path=nothing
database_data_aware=yes
dayofmonth=5
dayofweek=*
email_data_aware=yes
ftp_ip=127.0.0.1
ftp_local_file=/home/tmp/admin/user.admin.testuser.tar.gz
ftp_local_path=/home/tmp/admin
ftp_password=pass"word
ftp_password_esc_double_quote=pass\"word
ftp_path=/admin_backups
ftp_port=21
ftp_remote_file=user.admin.testuser.tar.gz
ftp_username=admin
hour=5
id=1
minute=0
month=1
owner=admin
select0=testuser
type=admin
value=multiple
when=now
where=ftp

3.1 How to Generate This Variable Dump


cd /usr/local/directadmin/scripts/custom
cp /var/www/cgi-bin/printenv ftp_upload.php
echo "exit 1;" >> ftp_upload.php
chmod 755 ftp_upload.php
./ftp_upload.php

After running a backup, the script will output all environment variables. Delete it afterward and create your own custom version if needed.


4. Using Backup ID to Trigger Custom Behavior


You can customize behavior based on backup ID. For example, if you want backup ID 1 to upload via SCP instead of FTP:


if [ "$id" = "1" ]; then
   # scp upload code
   exit 0;
fi

Note: “When: Now” does not pass an ID. Running “Run Now” on an existing cron job does pass the ID.


5. Converting ftp_upload.php to Use curl


DirectAdmin’s default uploader uses PHP’s FTP functions. For debugging or advanced setups, you can replace it with curl.


5.1 Copy the Script


cp -rp /usr/local/directadmin/scripts/ftp_upload.php \
/usr/local/directadmin/scripts/custom/ftp_upload.php

5.2 Replace Contents with curl Version


/bin/sh
ETH=eth0
CURL=/usr/local/bin/curl

result=`$CURL --interface $ETH -T $ftp_local_file \
-u $ftp_username:$ftp_password_esc_double_quote \
ftp://$ftp_ip$ftp_path$ftp_remote_file 2>&1`

if grep -qi "curl: (67) Access denied: 530" <<< "$result"; then
    echo "FTP access denied. Check login details."
    exit 1
fi
if grep -qi "curl: (6) Couldn't resolve host" <<< "$result"; then
    echo "Host could not be resolved."
    exit 1
fi
if grep -qi "curl: (9) Uploaded unaligned file size" <<< "$result"; then
    echo "File upload failed. Check path."
    exit 1
fi
if grep -qi "curl: Can't open" <<< "$result"; then
    echo "Can't open $ftp_local_file"
    exit 1
fi

Ensure ftp_path ends with a trailing slash.


6. Converting to ncftpput


/bin/sh
/usr/bin/ncftpput -t 25 -m \
-u "$ftp_username" -p "$ftp_password_esc_double_quote" \
"$ftp_ip" "$ftp_path" "$ftp_local_file" 2>&1
RET=$?
exit $RET

7. Original PHP‑Based Upload Method


/usr/local/bin/php


This is the default method used by DirectAdmin.


Written & researched by Dr. Shahin Siami