Skip to content

scp: avoid reconnecting to identical remote sources#698

Open
peripherium wants to merge 1 commit into
openssh:masterfrom
peripherium:fix/scp-reuse-connection
Open

scp: avoid reconnecting to identical remote sources#698
peripherium wants to merge 1 commit into
openssh:masterfrom
peripherium:fix/scp-reuse-connection

Conversation

@peripherium

Copy link
Copy Markdown

Implement the existing XXX in scp.c to reuse an SSH connection when the source user, host and port remain unchanged.

When processing multiple remote source arguments (e.g. scp -3 hosta:/foo hosta:/bar hostb:), scp currently reconnects to the same source host for each argument. This change reuses the existing connection until the source changes, avoiding unnecessary reconnects while preserving existing behaviour.

One question while working on this: tolocal() appears to exhibit similar behaviour when copying multiple files from the same remote host/user, reconnecting for each argument. Is there a reason for this, or would a similar optimisation there also be welcome?

@peripherium
peripherium force-pushed the fix/scp-reuse-connection branch from 5c6153d to 84e54c5 Compare July 10, 2026 15:43
Reuse an existing SSH connection when consecutive remote source arguments refer to the same user, host and port. This avoids unnecessary reconnections during remote-to-remote copies while preserving existing behaviour.
@peripherium
peripherium force-pushed the fix/scp-reuse-connection branch from 84e54c5 to 2b66f92 Compare July 10, 2026 18:17
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