scp
on Windows 11
Today I struggled quite a bit to successfully run scp
on Windows 11 and copy files to a remote SFTP server. It took quite some research to try and find out (without results) why the scp
command was hanging up on a line like the following (with -v
enabled):
[...]
debug1: Sending command: scp -v -t path/
The weird thing is that the same command would work perfectly on Linux, so it was definitely a Windows issue. My gut feeling was that scp
was not using the SFTP subsystem, but there was no -s
option (like in its Linux counterpart) to force its usage.
Running ssh -V
returned version 8.6. Knowing that SFTP is the default protocol starting from OpenSSH 9.0, I decided to upgrade OpenSSH. Luckily, the latest versions of OpenSSH include an MSI installer to make installation easier.
In a nutshell, this is what I had to do:
- Get the Win64 MSI installer from the latest release of OpenSSH (v9.5.0.0p1-Beta when I did this).
- Run the installer, which does not have a UI so it seems to exit abruptly, but it installs everything correctly.
Follow the instructions on the GitHub wiki, which basically involve updating the path with the following command in a PowerShell with admin rights:
[Environment]::SetEnvironmentVariable("Path", [Environment]::GetEnvironmentVariable("Path",[System.EnvironmentVariableTarget]::Machine) + ';' + ${Env:ProgramFiles} + '\OpenSSH', [System.EnvironmentVariableTarget]::Machine)
Close and reopen the terminal where I was using
scp
.Run
ssh -V
to confirm the update.
After the update, scp
ran without issues.