Skip to content

feat(android): upload shared files to host over SFTP - #67

Merged
involvex merged 1 commit into
mainfrom
cursor/share-to-host-sftp
Nov 26, 2026
Merged

involvex merged 1 commit into
mainfrom
cursor/share-to-host-sftp

Conversation

@involvex

@involvex involvex commented Nov 26, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • Accept Android ACTION_SEND / SEND_MULTIPLE file shares, stream content URIs into app cache, and upload via the existing SFTP transfer queue.
  • Route text shares to clone-as-before; file streams win when both are present. Session picker for multiple connections; Connect & upload profile picker when none.
  • Add hermetic coverage for text-vs-file routing, no-session guard, and named upload jobs; document in CHANGELOG / README / AGENTS / suggestions.

Related issues

N/A (release-batch item from suggestions 7.5)

Type of change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing behavior to change)
  • Documentation update
  • CI / tooling only

Platform tested

  • Android
  • Windows
  • Linux
  • macOS
  • iOS
  • Not applicable (docs/CI only)

Hermetic flutter analyze + targeted unit tests locally; device share-sheet still needs a manual APK install.

Test plan

  • flutter pub get
  • flutter analyze (no errors)
  • flutter test
  • Manual testing on device/emulator

Steps:

  1. Connect to a Windows host, share an image/file into PocketShell, confirm SFTP opens and the file lands in the current directory.
  2. With two connected sessions, confirm the session picker appears and uploads to the chosen one.
  3. With no session, confirm Connect & upload prompts for a profile; share a GitHub URL alone and confirm clone paste still works.

Screenshots / recordings

N/A (device share-sheet verification pending)

Checklist

  • My code follows the project style in analysis_options.yaml
  • I did not commit secrets, credentials, or private keys
  • I updated documentation if user-facing behavior changed
  • I added or updated tests where appropriate

Made with Cursor

Summary by Sourcery

Support sharing files from Android apps directly to a host through the existing SFTP transfer workflow.

New Features:

  • Add Android share-to-host support for single and multiple files, uploading shared content to an SFTP session’s current directory.
  • Provide session selection for multiple connections and profile selection with automatic connection when no session is active.

Enhancements:

  • Prioritize file shares over accompanying text while preserving existing text-to-clone handling.
  • Stream shared content into app cache and preserve display names for queued remote uploads.

Documentation:

  • Document Android share-to-host behavior and mark the corresponding product suggestion as shipped.

Tests:

  • Add coverage for share payload classification, shared-file parsing, session guards, upload name mapping, and named SFTP uploads.

Accept SEND/SEND_MULTIPLE file intents, cache them locally, and enqueue uploads through the existing SFTP queue with session or Connect-and-upload pickers.

Co-authored-by: Cursor <cursoragent@cursor.com>
@sourcery-ai

sourcery-ai Bot commented Nov 26, 2026

Copy link
Copy Markdown

Reviewer's Guide

Data structures

Introduce the shared-file payload and classify file shares ahead of accompanying text so downstream handlers receive the intended data.

  • lib/services/share_intent_service.dart L7-60

API

Expose named SFTP uploads and add the Android method-channel bridge for retrieving cached files from incoming share intents.

  • android/app/src/main/kotlin/com/involvex/ssh_app_flutter/MainActivity.kt L109-113 (+3 small edits)
  • lib/providers/sftp_controller.dart L404-419
  • lib/services/share_intent_service.dart L94-98, L124-145, L159-185 (+3 small edits)

Uses of the API

Connect the share-file events and cold-start payload to the upload handler, and enqueue pending uploads after the SFTP directory initializes.

  • lib/screens/home_screen.dart L151-159, L204-217 (+6 small edits)
  • lib/screens/splash_screen.dart L31-37, L46, L72-78
  • lib/widgets/sftp_browser.dart L14, L25-33, L59-87

Implementation

Implement share-to-host orchestration, including connected-session selection, profile connection, upload preparation, and the associated picker flows.

  • lib/services/share_upload_handler.dart L1-411

Capture SEND and SEND_MULTIPLE streams, copy each URI to cache without buffering whole files, and resolve safe display filenames.

  • android/app/src/main/kotlin/com/involvex/ssh_app_flutter/MainActivity.kt L27, L39-42, L124-229

UI

Register Android file-share MIME intent filters so the app appears as a target for single- and multi-file shares.

  • android/app/src/main/AndroidManifest.xml L47-56

Configuration

Document Android share-intent routing and the new share-to-host feature in repository guidance and release notes.

  • AGENTS.md L148
  • CHANGELOG.md L10-13

Documentation

Describe share-to-host in the README and mark the corresponding suggestion as shipped.

  • README.md L36
  • suggestions.md L170, L204

Tests

Verify named upload destinations, share-payload precedence, shared-file parsing, upload eligibility, and conversion to named upload items.

  • test/providers/sftp_controller_test.dart L193-223
  • test/services/share_intent_test.dart L10, L183-252

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@involvex
involvex marked this pull request as ready for review November 26, 2026 04:18
@sourcery-ai

sourcery-ai Bot commented Nov 26, 2026

Copy link
Copy Markdown

Sorry @involvex, you've used your own review budget of 250,000 diff characters for the last 7 days.

You can request another review in 3 days and 9 hours by commenting @sourcery-ai review. Upgrade to get a review now.

return uri.lastPathSegment
}

private fun sanitizeFileName(name: String): String {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

WARNING: Filename sanitization incomplete for Windows hosts

sanitizeFileName only replaces / and \ with _. Windows also forbids :, *, ?, ", <, >, | in filenames. Shared files with these characters will fail to upload to Windows hosts.

Suggested change
private fun sanitizeFileName(name: String): String {
private fun sanitizeFileName(name: String): String {
val trimmed = name.trim().ifEmpty { "shared_file" }
return trimmed.replace(Regex("[\\/:*?\"<>|]+"), "_")
}

}
}
Intent.ACTION_SEND_MULTIPLE -> {
val streams = readMultipleStreams(intent)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

WARNING: Stale state on empty SEND_MULTIPLE

If readMultipleStreams returns an empty list, the function returns early without clearing sharedText or sharedFiles. This leaves stale share data that could be processed incorrectly on the next intent.

Suggested change
val streams = readMultipleStreams(intent)
Intent.ACTION_SEND_MULTIPLE -> {
val streams = readMultipleStreams(intent)
if (streams.isEmpty()) {
sharedText = null
sharedFiles = null
return
}

"path" to outFile.absolutePath,
"name" to safeName,
)
} catch (_: Exception) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

SUGGESTION: Log exception for debugging

Catching all exceptions without logging makes it difficult to diagnose share failures in production. At minimum, log the exception.

Suggested change
} catch (_: Exception) {
} catch (e: Exception) {
android.util.Log.w("ShareIntent", "Failed to copy shared file", e)
if (outFile.exists()) {
outFile.delete()
}
null
}

final SSHProvider ssh = Provider.of<SSHProvider>(context, listen: false);
final List<SessionEntry> connected = connectedSessions(ssh);

onTabSelected?.call(AppTab.client);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

SUGGESTION: Switch tab only after validating upload can proceed

onTabSelected?.call(AppTab.client) is called before checking for connected sessions or available profiles. If no profiles exist, the tab switches but an error snackbar is shown, leaving the user on the Client tab with no actionable session.

Move the tab switch inside the success paths, or guard it with a check that upload will proceed.

if (controller == null) {
return;
}
await controller.init();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

WARNING: Upload attempted even if controller.init() fails

_bootstrap calls await controller.init() but doesn't check controller.error before proceeding to uploadNamedFiles. If init fails (e.g., no drives, connection issue), the upload will still be attempted and likely fail confusingly.

Suggested change
await controller.init();
await controller.init();
if (controller.error != null || !mounted) {
return;
}


_controller = SftpController(client: client);
unawaited(_controller!.init());
unawaited(_bootstrap());

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

SUGGESTION: Handle potential race in initState

unawaited(_bootstrap()) in initState means _bootstrap runs asynchronously. If the widget is disposed before _bootstrap completes, the mounted checks inside _bootstrap handle it, but consider using a StreamSubscription or Future-based pattern for clearer lifecycle management.

@involvex
involvex merged commit 10d323f into main Nov 26, 2026
8 checks passed
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