scp2 0.0.2-a0
scp real over ssh
License: MIT
Requires Python: >=3.8,<4.0

# scp2

scp (real) over ssh

适用于真的禁止了 scp 协议, 只开放 ssh 协议的场景

## Why

if only ssh is enable and scp/sftp disabled

## Usage

```bash
scp2 -f ./scp2/core.py -u user@IP:~/core.py
```

## How

如果真的只让有 ssh, 那么就用输入命令的方式来传输信息

write the file into command

1. `file` --> `base64` --> `chunk` --> `ssh.execute(echo "[chunk body]" >> /tmpfile)`

2. `ssh.execute(cat /tmpfile |tr -d '\n'|base64 -d > dest)`


It's real scp over the ssh.


### Example

```bash
scp2 -f ./scp2/core.py -u user@IP:~/core.py
```

the logs:

```
INFO:paramiko.transport:Connected (version 2.0, client OpenSSH_7.6p1)
INFO:paramiko.transport:Authentication (publickey) successful!
INFO:root:will temp write to /tmp/94d45061-5f4c-4bc4-9282-d60041952caf
INFO:root:echo "aW1wb3J0IGJhc2U2NAppbXBvcnQgaW8KaW1wb3J0IGxvZ2dpbmcKaW1wb3J0IHV1aWQKCmltcG9ydCBjbGljawppbXBvcnQgbW9yZV9pdGVydG9vbHMKaW1wb3J0IHBhcmFtaWtvCgoKZGVmIG5ld19zc2hfY29ubihob3N0LCBwb3J0LCB1c2VyKToKICAgIHNzaCA9IHBhcmFtaWtvLlNTSENsaWVudCgpCiAgICBzc2guc2V0X21pc3NpbmdfaG9zdF9rZXlfcG9saWN5KHBhcmFtaWtvLkF1dG9BZGRQb2xpY3koKSkKICAgIHNzaC5jb25uZWN0KGhvc3QsIHBvcnQsIHVzZXIpCiAgICByZXR1cm4gc3NoCgoKZGVmIGZpbGVfdG9fNjQoZmlsZSk6CiAgICB3aXRoIGlvLm9wZW4oZmlsZSwgJ3JiJykgYXMgZjoKICAgICAgICByYXdfY29udGVudCA9IGYucmVhZCgpCiAgICBiYXNlNjRfY29udGVudCA9IGJhc2U2NC5iNjRlbmNvZGUocmF3X2NvbnRlbnQpCiAgICBjb250ZW50ID0gYmFzZTY0X2NvbnRlbnQuZGVjb2RlKCd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3VyaScsIHJlcXVpcmVkPVRydWUsIGhlbHA9J3RoZSB0YXJnZXQgZGVzdCcpCkBjbGljay5vcHRpb24oJy1wJywgJy0tcG9ydCcsICdwb3J0JywgZGVmYXVsdD0yMiwgaGVscD0naG9zdCBwb3J0JykKZGVmIHNjcDIoZmlsZSwgdXJpLCBwb3J0KToKICAgIGhlYWQsIHRvZmlsZSA9IHVyaS5zcGxpdCgnOicpCiAgICB1c2VyLCBob3N0ID0gaGVhZC5zcGxpdCgnQCcpCgogICAgY29udGVudCA9IGZpbGVfdG9fNjQoZmlsZSkKCiAgICBsb2dnaW5nLmJhc2ljQ29uZmlnKGxldmVsPWxvZ2dpbmcu" >> /tmp/94d45061-5f4c-4bc4-9282-d60041952caf
INFO:root:echo "SU5GTykKCiAgICBzc2hfY29ubiA9IG5ld19zc2hfY29ubihob3N0PWhvc3QsIHBvcnQ9cG9ydCwgdXNlcj11c2VyKQoKICAgIHRtcGZpbGUgPSBmJy90bXAve3V1aWQudXVpZDQoKX0nCiAgICBsb2dnaW5nLmluZm8oZid3aWxsIHRlbXAgd3JpdGUgdG8ge3RtcGZpbGV9JykKCiAgICBjaHVua191cGxvYWRfdG1wKHNzaF9jb25uLCB0bXBmaWxlLCBjb250ZW50KQogICAgcmVidWlsZF9mcm9tX3RtcChzc2hfY29ubiwgdG1wZmlsZSwgdG9maWxlKQoKICAgIGxvZ2dpbmcuaW5mbygndXBsb2FkIHN1Y2Nlc3MnKQoKCmlmIF9fbmFtZV9fID09ICdfX21haW5fXyc6CiAgICBzY3AyKCkK" >> /tmp/94d45061-5f4c-4bc4-9282-d60041952caf
INFO:root:cat /tmp/94d45061-5f4c-4bc4-9282-d60041952caf|tr -d '
'|base64 -d > ~/core.py
INFO:root:rm /tmp/94d45061-5f4c-4bc4-9282-d60041952caf
INFO:root:upload success
```

## TODO

1. real scp, dirs, empty resurive ( lib.gnu.coreutils.click.headers )
2. better log
3. base64 or ?