To send or fetch files every night without opening FileZilla, use a cron job that runs the sftp command with an instruction file, or rsync over SSH. Both need key authentication, because nobody is there to type a password, and SSH switched on for your account. On MozOut’s shared servers the SSH port is 2299, and not every account has a shell.
When it makes sense
| Situation |
Direction |
Tool |
| Fetching a supplier’s price file every night |
From the supplier to you |
sftp with get, or rsync |
| Sending exports to a partner |
From you to the partner |
sftp with put |
| Copying backups to another server of yours |
From you to the other machine |
rsync |
Setting it up, step by step
| 1 |
Confirm your account has SSH. If you have the Terminal or “SSH Access” in cPanel, it does. See SFTP instead of FTP.
|
|
| 2 |
Create a key just for this job. In cPanel’s “SSH Access” you generate a pair. If the destination is another machine, the public key must be authorised there, on the account that will receive the files.
|
|
| 3 |
Connect once by hand, to accept the server’s fingerprint. Without that, the first connection from cron stops waiting for an answer that never comes.
|
|
| 4 |
Write the instruction file for sftp, with lines such as cd /folder and put /home/ACCOUNT/export.csv. The command is sftp -P PORT -i /home/ACCOUNT/.ssh/KEY -b /home/ACCOUNT/instructions.txt user@server. The -b runs in non-interactive mode.
|
|
| 5 |
Or use rsync: rsync -az -e "ssh -p PORT -i /home/ACCOUNT/.ssh/KEY" /home/ACCOUNT/backups/ user@server:/destination/. It only sends what changed.
|
|
| 6 |
Put the command in cron with a log, and check at the destination that the files arrived: cron jobs.
|
|
Rehearse before you schedule. rsync has a simulation option (-n, or --dry-run) that shows what it would copy without copying anything, and -v lists the files. Run it like that the first time and check the source and destination are where you think. A slash too many or too few at the end of a path changes the result.
A key with no passphrase, in a cron job, is a key that anyone who steals it can use. So use a key just for this job, with the destination account limited to the folder it needs, and read permission for you alone on the key file. Never put it inside public_html.
|
rsync has an option that deletes the source after sending (--remove-source-files). It is useful and dangerous: use it only after watching the copy work for several nights, and never on files that exist only there. For backup strategy, see making and keeping your own backup, and testing that it works.
|
If the supplier only offers FTP, ask for SFTP. Plain FTP sends the password unprotected. If there is nothing else, use FTP over TLS and keep that password for this job alone.
|
|
Not sure whether your account has SSH? Ask us, and we will tell you whether the plan includes it.
Open a ticket
|
RECOMMENDED PRODUCT Web hosting with cPanel Domain and SSL included, daily backups and the panel you already know. from $6.60/mo (3-year plan, with coupon) See plans |