I want to download files from a remote computer (destination), into my laptop (client). The remote computer is not accessible directly. I first have to SSH to a server then, from that server, SSH to the destination computer.
So my usual procedure to connect to the destination is to open a Linux terminal and write
Inserting the password, I am in the server terminal. I run
and I am in the destination terminal. I can do whatever I want there.
Note the server and destination addresses are in the form of either IPs or names. The server address is public and accessible from anywhere, but the destination address is local to the server network.
Now how can I download files from the destination to my laptop? read the next section.
The idea is to set a port on my laptop to point to a port on the destination computer. The SSH command is:
ssh -L aLaptopPort:destinationAddress:destinationPort myUsername@serverAddress
Because we are going to download files through ssh, I forward
port 22 of the destination.
To find listening ports on my laptop, I run the below command in the terminal:
sudo netstat -tulpn | grep LISTEN
So I choose a port that is not on the list. I usually use port 5901.
So the port forwarding command becomes like
ssh -L 5901:destinationAddress:22 myUsername@serverAddress
After inserting the password, you should be in the server terminal. Now port
5901 of my laptop points to port
22 of the destination. I leave the terminal open but we do not work with it.
To check the port is forwarded, in another terminal on my laptop I can run the
netstat command above.
If typing the command is time-consuming, you can create a bash alias for it like:
alias xyz="ssh -L 5901:destinationAddress:22 myUsername@serverAddress"
and paste it in
The previous command can be tucked into ssh config file placed in
~/.ssh/config by adding below lines
Host xyz HostName serverAddress LocalForward 5901 destinationAddress:22 User myUsername
Now in a terminal, I can forward the port via:
To download files I use FileZilla. Go to File->Site Manager. Push New site button. In the General tab, fill the fields like the picture below:
and finally, press Connect. Insert the password and you should see the files and folders of the destination in FileZilla.
The rest is easy, dragging files from the right window (destination) and dropping them in the left window (my laptop).
Here I use Linux Ubuntu but you can do the same on Windows with PuTTY or PowerShell.
The technique explained here can be used to connect to a remote printer, desktop and so on.
If you like this article, you may like this article too: Handy cross-platform packages to connect to a remote Linux server.
- Script to copy a directory path in Bash terminal
- What is the difference between .bashrc, .bash_profile, and .profile?
- A C++ MPI code for 2D arbitrary-thickness halo exchange with sparse blocks
- Create clone of a C++ class in polymorphic way
- How to use type erasure pattern to decouple polymorphic classes in C++?