Skip to content

Instantly share code, notes, and snippets.

@neutronscott
Last active February 24, 2024 23:02
Show Gist options
  • Save neutronscott/23ce66e01b4af69533e4079735516772 to your computer and use it in GitHub Desktop.
Save neutronscott/23ce66e01b4af69533e4079735516772 to your computer and use it in GitHub Desktop.
Let's use Windows openssh to get a local copy of a file ...

Using SFTP and SCP in Windows

SFTP

SCP is deprecated so let's start with SFTP:

C:\Users\snicholas\Downloads>sftp mute@192.168.1.1
mute@192.168.1.1's password:
Connected to 192.168.1.1.
sftp> cd '/tank/samba/public/Console Games/Wii'
sftp> ls -1 Rock*
Rock Band 2 [SZAE69]/
Rock Band 3 [SZBE69]/
Rock'n'Roll Adventures [RRAE5Z]/
sftp> cd 'Rock Band 3 [SZBE69]'
sftp> ls
SZBE69.wbfs
sftp> get SZBE69.wbfs
File "/tank/samba/public/Console Games/Wii/Rock Band 3 [SZBE69]/SZBE69.wbfs" not found.
sftp>

Well there is a way to make this work but for now let's try scp instead

SCP

How you'd expect it to work in bash:

C:\Users\snicholas\Downloads>scp "mute@192.168.1.1:/tank/samba/public/Console Games/Wii/Rock Band 3 [SZBE69]/SZBE69.wbfs" .
mute@192.168.1.1's password:
scp: /tank/samba/public/Console: No such file or directory
scp: Games/Wii/Rock: No such file or directory
scp: Band: No such file or directory
scp: Band: No such file or directory
scp: 3: No such file or directory
scp: [SZBE69]/SZBE69.wbfs: No such file or directory

OK obviously needs more quoting...:

C:\Users\snicholas\Downloads>scp "mute@192.168.1.1:/tank/samba/public/Console\ Games/Wii/Rock\ Band\ 3\ [SZBE69]/SZBE69.wbfs" .
mute@192.168.1.1's password:
scp: /tank/samba/public/Console: No such file or directory
scp: Games/Wii/Rock: No such file or directory
scp: Band: No such file or directory
scp: Band: No such file or directory
scp: 3: No such file or directory
scp: [SZBE69]/SZBE69.wbfs: No such file or directory

Oh yeah, of course backslashes inside double quotes wouldn't do...:

C:\Users\snicholas\Downloads>scp mute@192.168.1.1:'/tank/samba/public/Console Games/Wii/Rock Band 3 [SZBE69]/SZBE69.wbfs' .
mute@192.168.1.1's password:
bash: -c: line 1: unexpected EOF while looking for matching `''
The system cannot find the path specified.
The system cannot find the file specified.
The system cannot find the file specified.
The system cannot find the path specified.

bash -c? What am I running anyway?:

C:\Users\snicholas\Downloads>where scp
C:\Windows\System32\OpenSSH\scp.exe

Must be a wrapper for a bash script. Whatever let's keep trying:

C:\Users\snicholas\Downloads>scp "mute@192.168.1.1:'/tank/samba/public/Console Games/Wii/Rock Band 3 [SZBE69]/SZBE69.wbfs'" .
mute@192.168.1.1's password:
protocol error: filename does not match request

So the remote end is sending something but it isn't the name we expect because quoting magics are happening somewhere in the middle I guess. Just turn that CVE solving shit off:

C:\Users\snicholas\Downloads>scp -T mute@192.168.1.1:"'/tank/samba/public/Console Games/Wii/Rock Band 3 [SZBE69]/SZBE69.wbfs'" .
mute@192.168.1.1's password:
SZBE69.wbfs                                                                                                    100% 3922MB  60.5MB/s   01:04

Actually I did this after I gave up and remembered Windows has CIFS access to these files. But I'm a Linux user so I never think about that sort of point and click stuff. :D

Back to SFTP

Just remind SFTP what file you want:

sftp> get SZBE69.wbfs
File "/tank/samba/public/Console Games/Wii/Rock Band 3 [SZBE69]/SZBE69.wbfs" not found.
sftp> get '/tank/samba/public/Console Games/Wii/Rock Band 3 [SZBE69]/SZBE69.wbfs'
Fetching /tank/samba/public/Console Games/Wii/Rock Band 3 [SZBE69]/SZBE69.wbfs to SZBE69.wbfs
/tank/samba/public/Console Games/Wii/Rock Band 3 [SZBE69]/SZBE69.wbfs                 100% 3922MB  63.6MB/s   01:01
sftp>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment