← Blog
Three ivory packets in a lavender sorting tray, with an orange tab on the front packet.
Published on
2026-11-25

s5cmd batch transfers: copy, verify, and retry missing S3 objects

When s5cmd returns an error at the end of a parallel copy, some objects may already be in the bucket. In our four-file test, one source file was missing. The command exited with code 1, but both reports and an empty marker file had arrived. Listing the destination told us exactly which line to retry.

This guide walks through that transfer with s5cmd 2.3.0. You’ll preview a batch, recover from a partial copy and check the downloaded bytes against a manifest recorded before the upload. We used a local S3-compatible endpoint provided by Moto 5.2.6. The exercise measures correctness. Network performance, billing and the behavior of a particular provider need a separate test. Tested s5cmd release · Moto server documentation

Decide which files and keys belong in the batch

Use s5cmd run when you have a list of operations to carry out. Each line names a source and a destination. This works well when two objects share a filename but must keep different prefixes. For a single transfer, see the AWS S3 cp guide. If the job is to bring a changing directory and a bucket back into alignment, the AWS S3 sync guide explains how to decide which changes to apply.

To follow the commands, use PowerShell, Python 3.11 or later, and s5cmd on your path. Set $endpoint to the URL of your test service. Configure credentials for a disposable bucket that permits listing, reading and writing objects. The examples use an existing bucket named transfer-drill and an initially empty batch/ prefix. Substitute your own test bucket throughout if needed. Existing keys can be overwritten.

Run this Python snippet in a fresh working directory. The two reports have the same basename and different contents. The other filenames exercise a space and a zero-byte object.

from pathlib import Path

root = Path("source")
root.mkdir()  # Use a fresh working directory.
files = {"east/report.csv": b"id,total\n1,1250\n",
         "west/report.csv": b"id,total\n2,850\n",
         "notes/release notes.txt": b"approved for review\n",
         "empty.flag": b""}
for key, data in files.items():
    path = root / key
    path.parent.mkdir(parents=True, exist_ok=True)
    path.write_bytes(data)

Record a manifest before you upload

Save this as check_files.py. It pairs each relative path with its SHA-256 digest. Recording paths catches a report uploaded under the wrong name. Recording digests catches a different report under the correct name, even when the byte counts match. Keep the manifest outside the source tree and keep the source files stable throughout the transfer.

import argparse
import hashlib
import json
from pathlib import Path


def inventory(root):
    if not root.is_dir():
        raise ValueError(f"Directory does not exist: {root}")
    result = {}
    for path in sorted(root.rglob("*")):
        if path.is_file():
            with path.open("rb") as stream:
                result[path.relative_to(root).as_posix()] = hashlib.file_digest(
                    stream, "sha256").hexdigest()
    return result


if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    parser.add_argument("action", choices=["record", "check"])
    parser.add_argument("directory", type=Path)
    parser.add_argument("manifest", type=Path)
    args = parser.parse_args()
    if args.manifest.resolve().is_relative_to(args.directory.resolve()):
        parser.error("Keep the manifest outside the directory being checked")
    actual = inventory(args.directory)
    if args.action == "record":
        with args.manifest.open("x", encoding="utf-8") as out:
            json.dump(actual, out, indent=2)
    else:
        expected = json.loads(args.manifest.read_text(encoding="utf-8"))
        missing = sorted(expected.keys() - actual.keys())
        extra = sorted(actual.keys() - expected.keys())
        changed = sorted(k for k in expected.keys() & actual.keys() if expected[k] != actual[k])
        print(json.dumps({"missing": missing, "extra": extra, "changed": changed}))
        raise SystemExit(1 if missing or extra or changed else 0)

Save the four lines below as UTF-8 text in upload.txt. Quote each path separately. In particular, the space in release notes.txt belongs to the key. The four-worker limit keeps the example small. Actual transfer order can vary. s5cmd command and batch reference

cp "source/east/report.csv" "s3://transfer-drill/batch/east/report.csv"
cp "source/west/report.csv" "s3://transfer-drill/batch/west/report.csv"
cp "source/notes/release notes.txt" "s3://transfer-drill/batch/notes/release notes.txt"
cp "source/empty.flag" "s3://transfer-drill/batch/empty.flag"

Record the manifest and preview the batch. Compare the preview’s destination keys with the four paths under source. In our dry run all four appeared in the plan and the bucket still contained zero objects.

python check_files.py record source expected.json
s5cmd --endpoint-url "$endpoint" --numworkers 4 --dry-run run upload.txt

Read the batch error alongside the destination listing

To reproduce the partial failure, move the release notes aside after the preview, then run the same command file. Read the exit code before issuing another external command. The last line lists objects under the test prefix in JSON format.

Move-Item -LiteralPath 'source/notes/release notes.txt' -Destination 'withheld.txt'
s5cmd --endpoint-url "$endpoint" --numworkers 4 run upload.txt
$LASTEXITCODE
s5cmd --endpoint-url "$endpoint" --json ls 's3://transfer-drill/batch/*'

Our command exited with code 1 and identified the absent source file. The destination already held batch/east/report.csv, batch/west/report.csv and batch/empty.flag. Subtract the listed keys from the expected keys after accounting for the common batch/ prefix. This left one missing key. Also check for unexpected keys. A count of four would still be wrong if one expected path had been replaced by another.

For this test, save the missing operation as retry.txt:

cp "source/notes/release notes.txt" "s3://transfer-drill/batch/notes/release notes.txt"

Put the source file back, then run the one-line retry. List the destination again and confirm the exact four keys. On an existing destination, a matching name alone cannot establish that an old object contains the intended bytes.

Move-Item -LiteralPath 'withheld.txt' -Destination 'source/notes/release notes.txt'
s5cmd --endpoint-url "$endpoint" --numworkers 4 run retry.txt

Download to a clean directory and compare the bytes

Start with no received directory. This prevents a leftover local file from disguising a failed download. Save these lines as download.txt, then run the download and check the exit status of both commands.

cp "s3://transfer-drill/batch/east/report.csv" "received/east/report.csv"
cp "s3://transfer-drill/batch/west/report.csv" "received/west/report.csv"
cp "s3://transfer-drill/batch/notes/release notes.txt" "received/notes/release notes.txt"
cp "s3://transfer-drill/batch/empty.flag" "received/empty.flag"
s5cmd --endpoint-url "$endpoint" --numworkers 4 run download.txt
python check_files.py check received expected.json

All four paths and hashes matched in our run, including the zero-byte marker. As a control, we changed 850 to 851 in the downloaded west report. The file size stayed the same. The checker exited with code 1 and listed only west/report.csv under changed. Restoring its original byte content made the check pass again.

Use the same evidence before moving a larger collection

A clean comparison verifies the keys you checked and the bytes you read back. If the application also relies on metadata such as content type, cache headers or object tags, compare those separately. For an active source, freeze the test set or record a consistent version of it. Otherwise a legitimate change between hashing and copying can look like transfer damage.

For a migration to Object Storage with Hivenet, request a test bucket and repeat the round trip with a representative prefix. Include the file sizes and paths your application actually uses. Record total bytes, elapsed time, errors and the cost of verification reads before increasing the worker count. The local Moto run established how to detect and recover a partial batch. A test against your destination establishes how the transfer performs there.

Your next workload belongs on Hivenet.

Pick one AI, compute, or storage workload and see the difference for yourself. Spin it up in minutes, or let our team map your fastest path to production.