0

I haven't seen this issue before, and I have been struggling for days, so I would be so grateful for some help.

I have a tar on my Desktop (Desktop) that I am trying to copy to a remote server using scp -r.  However, without having a VPN set up (I can't – long story), I have to ssh into a remote server (let’s call it portal), and then ssh into the server I want to put the file in (destination).  I cannot figure out how to get the tar to destination.  I thought about trying to copy to portal first, which almost works, except there isn't enough space on portal to do this. Right now I have

scp -r path/to/Desktop/tar  login_to@portal:path/to/portal/could/place/file
but if I do
scp -r path/to/Desktop      login_to@destination:path/to/destination
it can't find destination, since I haven't gone through portal.  Any suggestions would be greatly appreciated!

6
  • There’s probably a better way, but a brute-force solution would be to break the file into smaller pieces, transfer them using two steps, and then reassemble them. Commented May 16, 2024 at 2:36
  • 6
    Can you ssh to the destination using ProxyJump on the portal? ssh -J login_to@portal login_to@destination? Commented May 16, 2024 at 3:30
  • Thank you all for the help. I tried scp -o ProxyJump=user@intermediate-login path/to/.tar user@destination-login/path/to/place/file and got the error that 'stat local "?\200\224o": No such file or directory' I even tried to unzip the tar and still got the same error Commented May 16, 2024 at 20:42
  • 1
    You are missing : after destination-login. Commented May 17, 2024 at 5:13
  • Sorry a mistype in typing it out here, but I do have the colon in the script @MartinPrikryl scp -o ProxyJump=user@intermediate-login path/to/tar/on/Desktop user@destination-login:/path/to/destination Commented May 21, 2024 at 1:27

2 Answers 2

0

I suggest abandoning scp for this purpose; instead, you should pipe tar through two ssh instances.

The following code snippet assumes that (a) ssh-agent is already running in your login environment (you can verify that with echo $SSH_AGENT_PID), (b) you have set up public key authentication for both portal and destination (i.e., populated ~/.ssh/authorized_keys properly on both portal and destination, and you have the matching private keys on Desktop).

# Load the identities (private keys) into ssh-agent on Desktop:
ssh-add ~/.ssh/id_rsa_for_portal
ssh-add ~/.ssh/id_rsa_for_destination

# Create a tape archive on Desktop, pipe it over portal, extract it
# on destination.
tar -c file1 file2 ... \
| ssh -A portal ssh destination tar -x -v

The ssh command that you run on Desktop will:

  • log in to portal without asking for a password,
  • not allocate a pseudo-terminal on portal,
  • forward the ssh agent connection to portal,
  • launch the command ssh destination tar -x -v on portal.

The ssh command run thusly on portal will:

  • log in to destination without asking for a password (thanks to the forwarded agent connection),
  • not allocate a pseudo-terminal on destination,
  • launch the command tar -x -v (extract verbosely) on destination.

The stdout of the local tar command (on Desktop) will be forwarded over both ssh connections to the stdin of the remote tar on destination. The remote tar process will extract the files, list their names on stdout (which is going to be forwarded back to your local ssh command's stdout, on Desktop), and report any errors on stderr (which is going to be forwarded back to your local ssh command's stderr). The exit status of the remote tar process will be reflected as the exit status of the local ssh command, on Desktop.

-2

Try this and see if it helps. Use nfs to export the file on your desktop and mount it on your destination . Then copy it from the mount point to the required location on your destination using copy command.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.