1

I have three computers HOME, WORK and SERVER and I am connected from HOME to SERVER by:

ssh -t <WORKusername>@<WORK> ssh -p23456 <SERVERusername>@localhost

I need to transfer the file from HOME to SERVER but I am not able to leave the file in WORK

Also I would need to transfer a file from the SERVER to HOME after processing it, how do i do it?

I have took a look at https://serverfault.com/questions/37629/how-do-i-do-multihop-scp-transfers and scp between two remote hosts from my (third) pc but i am unable to change the ssh config on the HOME machine

And i've tried this but i got nowhere:

$ scp -o ProxyCommand="ssh <WORKusername>@<WORK> nc localhost" ASPEC.zip <SERVERusername>@localhost:~/
<WORKusername>@<WORK>'s password: 
This is nc from the netcat-openbsd package. An alternative nc is available
in the netcat-traditional package.
usage: nc [-46DdhklnrStUuvzC] [-i interval] [-P proxy_username] [-p source_port]
      [-s source_ip_address] [-T ToS] [-w timeout] [-X proxy_protocol]
      [-x proxy_address[:port]] [hostname] [port[s]]
ssh_exchange_identification: Connection closed by remote host
lost connection

I've also tried the following but this is the reverse to transfer file from SERVER -> HOME:

ssh -t <WORKusername>@<WORK> "ssh -p 23456 <SERVERusername>@localhost \"cat file.zip\""

I've also tried tar but it didn't work:

tar c file.zip | ssh -t <WORKusername>@<WORK> "ssh -p 23456  <SERVERusername>@localhost | tar x"
Pseudo-terminal will not be allocated because stdin is not a terminal.
<WORKusername>@<WORK>'s password: 
Pseudo-terminal will not be allocated because stdin is not a terminal.
Permission denied, please try again.
Permission denied, please try again.
Permission denied (publickey,password).
tar: This does not look like a tar archive
tar: Exiting with failure status due to previous errors

Then I tried:

# From home:
$ ssh -L 23456:<SERVERusername>@localhost:22 <WORKusername>@<WORK>

# After ssh, in WORK:
$ ssh -p 23456 <SERVERusername>@localhost

# From home:
$ scp -P file.zip <SERVERusername>@localhost:~/

And i got these error when i give the scp command,

# on WORK terminal:
channel 3: open failed: administratively prohibited: open failed

# on SERVER terminal:
ssh_exchange_identification: Connection closed by remote host
lost connection

I've also tried rsync but it didn't work:

rsync -e "ssh -A -t <WORKusername>@<WORK>e ssh -p23456 <SERVERusername>@localhost" file.zip :~/

How can I scp from HOME to transfer a file to SERVER?

And also from SERVER to HOME?

alvas
  • 135
  • 3
  • 17

2 Answers2

4

Try to use this:

scp -P SERVERPORT -o 'ProxyCommand ssh -p WORKPORT WORKUSER@WORK nc %h %p 2>/dev/null' localfile SERVERUSER@SERVER:remotefile

ProxyCommand create the proxy on WORK host that connected to SERVER:SERVERPORT (see nc). %h and %p are ssh variables - target host and port respectively.

0

You can try something like:

cat localfile | ssh <WORKusername>@<WORK> "ssh -p23456 <SERVERusername>@localhost 'cat > remotefile'"