Skip to content

fix(ftp): force binary transfer mode to prevent corrupt downloads - #34

Open
dialupdisaster wants to merge 2 commits into
mainfrom
fix/ftp-binary-transfer-mode
Open

dialupdisaster wants to merge 2 commits into
mainfrom
fix/ftp-binary-transfer-mode

Conversation

@dialupdisaster

Copy link
Copy Markdown
Contributor

Description

FTP sessions never sent TYPE at all, so every connection stayed on the server's default transfer type — usually TYPE A (ASCII) per RFC 959. ASCII mode rewrites line endings, which silently corrupts every binary file transferred through FTP or Nitrado (game saves, archives, SQLite databases).

This sets TYPE I once after login and before any RETR/STOR, so it applies to both backup downloads and remote restore uploads. Nitrado inherits the behaviour because it delegates to FtpConnector. SFTP is unaffected.

It also adds a post-download size check: if the number of bytes written does not match the size reported by the connector, the backup aborts instead of archiving corrupt data.

Type of change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update
  • Refactor/chore

Checklist

  • I have read CONTRIBUTING.md
  • cargo fmt --all -- --check passes locally
  • cargo clippy --all-targets -- -D warnings passes locally
  • cargo test --all-targets passes locally (109 tests)
  • cargo build --release passes locally
  • I added or updated tests where appropriate
  • I updated docs/config examples if behavior changed (n/a: no config or CLI change)
  • Commit messages follow Conventional Commits

Related issues

None.

suppaftp never sends TYPE on its own, so the session stayed on the server default (usually TYPE A per RFC 959). ASCII mode rewrites line endings and silently corrupted every binary file downloaded via FTP/Nitrado. Issue TYPE I right after login, before any RETR/STOR, for both the FTP and Nitrado connectors (Nitrado delegates to FtpConnector).
Verify the bytes written for each file against the size reported by the connector so silent transfer corruption (for example an ASCII-mode FTP session) aborts the backup instead of producing a corrupt archive. Files whose size is unknown (reported as 0) are skipped.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 21, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-21T02:48:52.725709Z 26384f0 PR opened
🔒 Security Review ✅ Completed 2026-11-21T02:50:21.746265Z 26384f0 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 26384f0433

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/backup/manager.rs
Comment on lines +109 to +110
if file.size > 0 && downloaded != file.size {
bail!(

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Revalidate remote metadata before rejecting a size mismatch

When backing up a running server, a log or save file can grow between the initial conn.list() and its download. Both FTP and SFTP collect sizes during directory traversal, then download files sequentially without locking or snapshotting them, so a successful binary transfer can legitimately contain more bytes than the stale listing reports. This check now aborts the entire backup without creating an archive in that situation, including for SFTP. Recheck the remote metadata and distinguish a changed source file from a truncated transfer, with an appropriate retry or explicit policy for changing files.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant