0

Suppose that I ssh into some sever. Is there any way to write a python script such that I can run it, and it will transfer some file that is on the server, say "abc.json" , back into the local machine that I am on?

I am very new to networking in general, but I am aware that you can use scp in bash to transfer files. However, the only way I know requires a destination IP, which only works for specific cases and not for a more general case where I can ssh from any machine and transfer the files back into that machine.

Sorry if the question is bad or does not make sense, I am very new to networking.

  • https://stackoverflow.com/questions/68335/how-to-copy-a-file-to-a-remote-server-in-python-using-scp-or-ssh – waynetech Jul 11 '19 at 17:39
  • Does it have to be python? There are several other easier ways to do this. – Joe Jul 11 '19 at 17:40
  • I prefer python but am open to other methods to do it – gangsignwall Jul 11 '19 at 17:55
  • Just to make sure I understand you. What you want is: First `ssh` from computer `A` to to a remote machine `B`. Then run a command on `B` like: `cp-home file.txt` which will have the effect that `file.txt` is transferred back using the existing `ssh`-connection to the computer `A`'s file system? – Ente Jul 11 '19 at 19:32
  • @Ente Yes that is correct. – gangsignwall Jul 15 '19 at 16:48
  • Hmm.. you could run a ssh server on `A` and remote-forward (`-R`) a certain port on `B` to that ssh server. Then send files from `B` via that forwarded port back to `A`. This is a bit cumbersome and I cant really see an advantage from this over directly connecting back to `A`. – Ente Jul 18 '19 at 19:43

0 Answers0