Short answer: SFTP has no built-in diff, so to see what will change you need to compare the remote file with your local copy yourself. In a terminal, download the remote file and run diff -u remote local. In a graphical client, use one that shows a line-by-line diff as part of the upload step, such as Quarry on Mac.
SFTP transfers files. It does not tell you what is different, and it will replace a remote file with whatever you send. If you upload the wrong version of a production config, the original is gone unless you saved a copy. A diff before every upload catches most of these mistakes.
Why a diff before upload matters
Most bad overwrites come from a small set of situations:
- The remote file changed after you downloaded it. Someone else, or a deploy script, edited it. Your upload wipes out their change.
- You edited an old local copy. You have two versions on disk and picked the stale one.
- You uploaded to the wrong host or path. Staging and production look alike.
- You changed more than you meant to. An editor reformatted the file, changed line endings, or stripped trailing whitespace across the whole file.
A diff shows all four before anything is sent. If the diff has lines you did not write, stop and find out why.
Method 1: compare in the terminal
This works on any Mac or Linux machine with no extra software.
Download the remote file, then diff
sftp user@host:/etc/nginx/nginx.conf /tmp/remote-nginx.conf
diff -u /tmp/remote-nginx.conf ./nginx.conf
diff -u prints a unified diff: lines starting with - exist only in the remote copy, lines starting with + exist only in yours. If the output is empty, the files are identical and there is nothing to upload.
Or diff over SSH without saving a file
If you have SSH access, you can stream the remote file straight into diff:
ssh user@host 'cat /etc/nginx/nginx.conf' | diff -u - ./nginx.conf
The - means "read from standard input", so the remote file is compared as the left side. This needs shell access on the server, which SFTP-only accounts may not have.
Keep a copy of the original
A diff tells you what will change. It does not let you undo the change. Save the original before you upload:
cp /tmp/remote-nginx.conf ./nginx.conf.bak-$(date +%F)
Limits of the manual method
It works, but it depends on you remembering to run it, every time, under time pressure. It does not warn you if you picked the wrong host. And restoring means finding the backup and uploading it again by hand.
Method 2: use a GUI diff tool
You can open both files in a diff tool such as the one built into your editor, or the opendiff command (it opens FileMerge, which is part of Xcode):
opendiff /tmp/remote-nginx.conf ./nginx.conf
This gives a side-by-side view. It is still a separate step from uploading, so the same risk applies: it is easy to skip.
Method 3: use an SFTP client that diffs as part of the upload
Quarry builds the diff into the flow, so it is hard to skip:
- Connect to a saved host with an SSH key or password.
- Open the remote file and edit it.
- Review the diff. Your local copy against the remote file, line by line.
- Upload. Quarry warns before it overwrites, and keeps a local snapshot of the original first.
- Roll back if needed. If the upload was a mistake, restore the snapshot in one click.
The diff, the overwrite guard and the snapshot work together: the diff is how you catch the mistake, and the snapshot is how you recover when you miss one. Everything is logged locally in an activity log with timestamps, so you can see what was uploaded and when.
Quarry requires macOS Sonoma 14.6 or later and is focused on SFTP. The free version supports one saved connection; paid plans are a one-time $9, $19 or $39. See the feature overview.
A pre-upload checklist for production files
Whatever tool you use, this routine prevents most incidents:
- Confirm the host and path. Read the connection name and the full remote path.
- Diff the file. Read every changed line, including whitespace and line endings.
- Keep the original. A snapshot or a dated backup.
- Upload.
- Verify. Test the config (
nginx -t,apachectl configtest, a syntax check) before you reload the service. - Know your way back. Before you start, know how you would restore the original.
What a diff will not tell you
- Whether the file is correct. A clean diff means "this is what changes", not "this works".
- Permissions and ownership. Most diffs compare content only. Check mode and owner separately if they matter.
- Other files. A change to one file can break another that depends on it.
- Changes made after you looked. If the remote file can change at any moment, a diff is only as fresh as the moment you ran it. For high-traffic servers, keep the gap between diff and upload short.
Can you diff whole directories?
With the terminal, you can compare two local directories with diff -r, so you would download the remote directory first, for example with sftp and get -r, or with rsync over SSH if you have shell access. For a safe preview of what rsync would change, use its dry-run flag:
rsync -avn --itemize-changes ./site/ user@host:/var/www/site/
-n shows what would be transferred without doing it. Note that this lists which files differ; for what changed inside a file, you still need a diff.
Related guides
Frequently asked questions
Does SFTP have a built-in diff or compare command?
No. The SFTP protocol transfers and manages files; it has no command to compare a local and a remote file. You compare them with diff or a client that does it for you.
How do I compare a local file and a remote file over SFTP?
Download the remote copy with sftp or scp, then run diff -u remote local. If you have SSH access, ssh user@host 'cat path' | diff -u - local does it without saving a file.
How do I upload a file with SFTP?
In a terminal, connect with sftp user@host and use put localfile remotepath. In a graphical client, drag the file into the remote pane.
Can I undo an SFTP upload?
Only if you kept a copy of the original. SFTP itself has no undo. Quarry saves a local snapshot before it replaces a remote file, so you can restore it in one click.
Is SFTP faster than FTP?
Speed depends on the server, network and client rather than the protocol label alone. SFTP encrypts traffic, which adds some overhead, but for most developer tasks the difference is not what limits you. The reason to choose SFTP is security: it runs over SSH and encrypts credentials and data.
Try it on one server
Download Quarry and open a remote file on the free plan to see the diff step in action.
