0

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?

  • Did you try to scp from home to work and then from work to server? Something like this (from head; might not work out of the box): scp <localfile> <workusername>@<work>:/tmp/<filename> && ssh -t <WORKusername>@<WORK> scp -P23456 /tmp/<filename> <serveruser>@localhost:/<somedirectoryontheserver> So first you scp it to your work and then you give (via ssh) the command to your work computer to scp it further to the server. It puzzles me though why you connect to server via localhost. Is is a virtual server on your work computer? If it works I'll transfer it to the answer section. – agtoever Aug 19 '14 at 7:18
3
+50

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.

  • thanks it works but how do i do the reverse from SERVER to HOME? – alvas Aug 20 '14 at 8:01
  • same way, just swap SERVERUSER@SERVER:remotefile and localfile, like: scp -P SERVERPORT -o 'ProxyCommand ssh -p WORKPORT WORKUSER@WORK nc %h %p 2>/dev/null' SERVERUSER@SERVER:remotefile localfile – go1dshtein Aug 20 '14 at 8:41
  • i'm getting ssh_exchange_identification: Connection closed by remote host when transferring from HOME to SERVER =( – alvas Aug 20 '14 at 8:53
  • ah typo errrors, now it works, woohoo!! thanks a million!!!! – alvas Aug 20 '14 at 8:58
0

You can try something like:

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.