Back to blog
Guide9 min read|

November 20, 2026

How to Verify File Integrity After an SFTP Transfer

Verify file integrity after an SFTP transfer with SHA-256 checksums: what SSH already protects, sidecar files, batch manifests and scripts you can run.

How to Verify File Integrity After an SFTP Transfer

A partner uploads a 2 GB export over SFTP. The client reports success, your job picks the file up, and the import fails halfway through with a parse error on a line that does not exist. The transfer "worked", but the file you processed is not the file they sent. If you need to verify file integrity after an SFTP transfer, a successful exit code is not enough evidence.

This guide explains what SFTP and SSH already guarantee, where corruption and truncation actually come from, and how to set up SHA-256 checksum verification with sidecar files, manifests and a small script you can drop into an existing pipeline.

What SSH already protects, and what it does not

SFTP runs inside an SSH connection, and every SSH packet carries a message authentication code (or uses an authenticated cipher such as AES-GCM or ChaCha20-Poly1305). If a bit flips on the wire, or someone tampers with traffic in transit, the connection fails. So in-flight corruption between client and server is not your problem.

The gaps are everywhere else:

  • Interrupted transfers - A dropped connection or killed process leaves a partial file on the server. Many clients and scripts do not clean it up, and a downstream job happily reads the first 1.4 GB.
  • Resumed uploads - Resume features (reput, put -a, or a GUI client's "resume") append to whatever is already there. If the partial file on the server was itself wrong, the resumed file is wrong too.
  • Wrong source file - The partner's export job ran twice, or ran before the database finished writing. The bytes transferred perfectly; they were just the wrong bytes.
  • Processing too early - Your consumer picks up a file while the upload is still in progress. Nothing is corrupt, it is simply incomplete at the moment you read it.
  • Storage and copy steps - Files are often copied again after arrival: to an archive, to an object storage bucket, to an ERP pickup folder. Each hop is another chance to truncate or mix up files.

SSH guarantees that each packet arrived as sent. It says nothing about whether the complete file on disk matches the complete file the sender intended. That end-to-end check is your job.

Why SFTP has no built-in checksum

Most SFTP servers, including OpenSSH's sftp-server, implement version 3 of the protocol, which has no command for "give me the hash of this file". Later drafts of the SFTP specification defined a check-file extension, and a few servers support it, but OpenSSH does not and you cannot rely on a partner's server having it.

The usual workaround of running ssh host sha256sum /path/file only works if you have shell access. Properly locked-down SFTP accounts do not, by design. So integrity checks have to be built from plain file operations: compute a hash on one side, transfer it alongside the data, and recompute it on the other side.

Picking a hash algorithm

Use SHA-256 unless something forces you otherwise.

  • SHA-256 - Fast enough for multi-gigabyte files, available on every platform, and collision resistant. It protects against accidental corruption and deliberate substitution.
  • MD5 and SHA-1 - Still common in older partner integrations. They catch accidental corruption fine, but both have practical collision attacks, so they should not be your evidence that a file was not swapped. Accept them from legacy partners if you must, and plan a move to SHA-256.
  • CRC32 and file size - Useful as a quick first filter, not as verification. Two different files of the same size are easy to produce by accident.

The command is the same idea on every operating system:

# Linux
sha256sum orders-2026-11-20.csv

# macOS
shasum -a 256 orders-2026-11-20.csv

# Windows PowerShell
Get-FileHash -Algorithm SHA256 .\orders-2026-11-20.csv

Note that PowerShell prints the hash in uppercase while the Unix tools print lowercase. Compare case-insensitively or normalize to lowercase, or a correct file will fail verification.

Sidecar checksum files

The simplest convention is a sidecar file: for every orders.csv, the sender also uploads orders.csv.sha256 containing the hash. The standard format is the one sha256sum produces, which is the hash, two spaces and the filename:

3f7a1c9e0b5d4e2f8a6c7b9d1e3f5a7c9b1d3e5f7a9c1b3d5e7f9a1c3b5d7e9f  orders-2026-11-20.csv

Using this exact format means the receiver can verify with a single built-in command:

sha256sum -c orders-2026-11-20.csv.sha256
# orders-2026-11-20.csv: OK

The order of operations matters more than the format. The sender should:

  1. Generate the file completely.
  2. Compute the checksum from the final file on disk.
  3. Upload the data file, ideally to a temporary name such as orders-2026-11-20.csv.part, then rename it.
  4. Upload the .sha256 sidecar last.

Uploading the sidecar last turns it into a completion marker. The receiver never touches a data file until its sidecar exists, which solves the "processing too early" problem and the integrity problem with one convention. The temporary-name-then-rename pattern is covered in more detail in the SCP vs SFTP comparison, since it is one of the reasons to prefer SFTP for unattended jobs.

A sender-side script with OpenSSH's sftp client in batch mode looks like this:

#!/usr/bin/env bash
set -euo pipefail

FILE="orders-2026-11-20.csv"
sha256sum "$FILE" > "$FILE.sha256"

sftp -b - partner@sftp.example.com <<EOF
cd inbound
put $FILE $FILE.part
rename $FILE.part $FILE
put $FILE.sha256
EOF

With -b, sftp aborts on the first failed command, so a failed upload never gets as far as publishing the sidecar.

Manifests for batches

When a partner sends many files together (a day's invoices, a set of related tables), per-file sidecars get noisy and do not tell you whether the batch is complete. A manifest does both. It is a single file listing every file in the batch with its hash:

9b2e...41ac  invoices/INV-10231.xml
c71d...0e9f  invoices/INV-10232.xml
5a88...d3b2  invoices/INV-10233.xml

Generate it with sha256sum invoices/*.xml > manifest-2026-11-20.sha256 and upload it after every file in the batch. On the receiving side, sha256sum -c checks each listed file. A missing file shows up as an error, which catches the "two of three files arrived" case that per-file checks miss. Some teams add a line count or total byte count to the manifest name or a header so a truncated manifest is also detectable.

How to verify file integrity after an SFTP transfer on the receiving side

On the receiving side, a short Python script can watch for sidecars, verify the matching data file and move it on or set it aside. It streams the file in chunks, so memory use stays flat even for very large files:

import hashlib
import shutil
import sys
from pathlib import Path

INBOUND = Path("/data/inbound")
READY = Path("/data/ready")
QUARANTINE = Path("/data/quarantine")

def sha256_of(path: Path) -> str:
    h = hashlib.sha256()
    with path.open("rb") as f:
        for chunk in iter(lambda: f.read(1024 * 1024), b""):
            h.update(chunk)
    return h.hexdigest()

for sidecar in INBOUND.glob("*.sha256"):
    expected, _, name = sidecar.read_text().strip().partition("  ")
    data = INBOUND / name
    if not data.exists():
        print(f"missing data file for {sidecar.name}", file=sys.stderr)
        continue

    actual = sha256_of(data)
    target = READY if actual == expected.lower() else QUARANTINE
    shutil.move(data, target / data.name)
    shutil.move(sidecar, target / sidecar.name)
    print(f"{data.name}: {'OK' if target is READY else 'MISMATCH'} -> {target}")

Run it from cron or, better, trigger it when a sidecar arrives. The event-driven file processing guide shows how to replace a polling loop with upload webhooks.

Verify again after every hop

Integrity is not only about the partner-to-server leg. Every time your own pipeline copies or moves a file, there is another opportunity for truncation or a mixed-up path. Three habits help:

  • Carry the hash with the file - Keep the verified checksum in metadata, a database row or the sidecar itself, and recheck it after each copy to an archive, bucket or pickup folder.
  • Hash before delete - When a move is implemented as copy-then-delete, verify the copy before deleting the source. A failed copy followed by a successful delete is how files disappear.
  • Record the hash in your logs - Logging the SHA-256 of every file you accepted gives you something concrete to compare against when a partner says "we sent the right file". It also makes duplicate detection trivial, as described in the CSV validation tutorial.

Object storage has its own integrity features. AWS S3, for example, can store a SHA-256 checksum supplied at upload time. Support varies across S3-compatible providers, and the default ETag is not a reliable content hash for multipart uploads, so do not treat it as one.

Common pitfalls

  • Hashing a file that is still being written - The sender computes the checksum before the export job finishes flushing. The hash is valid for the wrong bytes. Hash the final file, not the stream.
  • Line ending conversions - A file opened and resaved on Windows, or transferred through a tool with text mode enabled, changes \n to \r\n. The content looks identical and the checksum fails. This is a real mismatch, not a false alarm.
  • Filename drift in the sidecar - The sidecar says export.csv but the file was renamed to orders-2026-11-20.csv on upload. sha256sum -c then reports a missing file. Agree on whether the sidecar contains the final name.
  • Case and whitespace - Uppercase hashes from PowerShell, trailing newlines, a single space instead of two. Normalize before comparing.
  • Silently ignoring mismatches - A mismatch that only prints to a log nobody reads is no better than not checking. Route failures to quarantine and alert someone, and see the partner onboarding guide for building the integrity check into go-live testing.

How FilePulse fits

FilePulse is a fully managed, EU-hosted file transfer service, so you do not run the SFTP server or the scripts around it yourself. Workflows trigger when a file arrives over SFTP, FTPS, WebDAV or the API and can validate checksum, size, name and file type before anything else happens. Files that fail validation go to a quarantine inbox, where they can be inspected and replayed once fixed, and you can be notified by webhook or email. Copies, moves and renames inside a workflow are verified by SHA-256, and each action is recorded in a tamper-evident, hash-chained audit log.

Next step: Start a 14-day free trial of FilePulse, no credit card required, and add a checksum validation step to your first inbound workflow.