Is there a way to make an SFTP connection to a remote machine through jump server to transfer files?

I was wondering if there's a way to send files using SFTP to a remote machine through a jump server. As you can see in the image below first it's needed an SSH connection and after that an SFTP connection.

enter image description here

My main problem here comes after the SSH connection, my workspace has changed and I cannot retrieve the necessary files to execute the SFTP successfully. I've tried the following code:

ssh jump-server-user@ip-jump-server 'echo "put /source/files /remote/files" | sftp -v remote-machine-user@ip-remote-machine'

But it does not work.

I've tried to execute a simple command like pwd using the SFTP connection and it works so I think the problem here is how the workspace change.

There would probably be an easier solution but I cannot use SSH on the jump server-remote machine connection and I cannot store the local files in the jump server to send them later to the remote machine.


If you have a recent OpenSSH (8.0) locally, you can use the -J (jump) switch:

sftp -J jump-server-user@ip-jump-server remote-machine-user@ip-remote-machine

With older version (but at least 7.3), you can use ProxyJump directive:

sftp -o ProxyJump=jump-server-user@ip-jump-server remote-machine-user@ip-remote-machine

There are other options like ProxyCommand or port forwarding, which you can use on even older versions of OpenSSH. These are covered in Does OpenSSH support multihop login?