How to transfer files using command-line from Terminal

A pen tester should be well equipped with different tricks to transfer files from a remote server as well from one directory to another. In this tutorial, we shall discuss different ways to transfer files using the command-line.

Transferring exploits, python scripts, and loading modules are often needed during penetration testing activities. Since the terminal is the tool used mostly, its essential to understand the basics of the file transfer.

A pen tester should be well equipped with different tricks to transfer files from a remote server as well from one directory to another. In this tutorial, we shall discuss different ways to transfer files using the command-line.

1. Python Server

Python is the basic package that comes preinstalled in almost all the Debian based systems. To transfer a file from one machine to another, do the following;


Switch to the directory where your file that you want to transfer exists. Start a simple python server. Enter the following command;

$ python -m SimpleHTTPServer 8080

Now go to the machine where you want to transfer the file. Use the following command to download the file;

$ wget

Remember to replace the IP, Port number & name of the file.


Anything written in python2 will almost always break in python3. So we also look at how to transfer a file using python3.

In the case of python3, enter the following command to start a simple python server.

$ python3 -m http.server 8080

To download the file on the target, enter the following command;

$ wget

Python3 File Transfer
Python3 File Transfer

2. Netcat

Netcat is a powerful utility to transfer files from any remote machine to a local machine. It may not always be installed. You can check whether it exists or not by entering;

$ which netcat
Alternatively, by entering;
$ which nc

Make a netcat server with the following command;

$ nc -nlvp 8080 < evil.php

Now go to the target machine and enter the following to download the file;

$ nc -nv 8080 > evil.php

Netcat file transfer
Netcat file transfer

Replace nc with netcat in the above commands if nc doesn’t work or is not installed correctly.

3. SCP

Secure Copy Protocol is a powerful tool for transferring files. It comes in handy especially when you want to transfer directories. Its also mostly used for file transfers over ssh.

For transfer file via ssh, enter the following command on sending machine;

$ scp -i new.pem [email protected]:/home/ubuntu
Where -i represents the public key for ssh login, is the file to be transferred and /home/ubuntu is the target directory where we want to save the file.

SCP Remote File Transfer
SCP Remote File Transfer

To download a file from the remote machine, enter the following command;

$ scp [email protected]:/remote_directory/file /local/directory

SCP Local File Download
SCP Local File Download


You can use this third-party tool to transfer files. It can be useful when you don’t have a machine with public IP, and you still have to transfer the files. The following command uploads the file to the servers;

$ curl --upload-file ./file.txt

To download the file, enter the following command;

$ curl -o file.txt is still under development and may not work always.


Command-line tools give us the ability to transfer files in various ways. They may seem a bit complicated but getting hands-on them gives the capability to easily manage files, especially when a GUI option is not available.

Zohaib Yousaf
My name is Zohaib Yousaf. I'm an Ethical Hacker & a Pen Tester. Python scripting and Bash automation is my hobby. My research work is in Anonymity. I have co-worked in development of few anonymity solutions which implemented different Cryptographic Algorithms.


Please enter your comment!
Please enter your name here




terminate frozen app
For dealing with a frozen app or desktop, you can't use the CTRL+ALT+DEL in Linux system. Instead, there are powerful alternatives that come in handy in frustrating situations. We pick the best methods available for you.
Uninstall Programs in Ubuntu
Uninstallation of programs can be done by graphical way using the Ubuntu Software Center, and the Synaptic Package manager. Command-line way of doing it is also possible using apt-get and aptitude commands. We shall discuss each one of them in detail.
screen capturing apps for linux
Do you want to make a video tutorial for YouTube or show-off your epic victory royale to your friends? Look no further — as we have compiled the 10 Best Screen Capturing Software for Linux. Whether you need to record your desktop screen or take a simple screenshot, FOSSLinux has got your back.
Free up hard disk space ubuntu
Hard disk space can easily get filled up with cached package files, old kernels, and other obsolete files that occupy unwanted hard disk space. Here are top five best and safer ways to clean and free up hard disk space in Ubuntu. We show you Terminal and GUI way of cleaning up system.
best linux distros programmers
Linux distros have long been a favorite among programmers since the rise in popularity of the OS in the nineties. Programmers are technical by nature, and Linux distros appeal to that technical nature. Let's discuss why Linux is a great desktop OS for programmers and developers, and find out best distros suitable for them.