icon

File Transfer in Linux

Last modified: 2024-10-03

Using Wget

In machine A, Start a web server.

python -m http.server

# We can specify which directory to host by `--directory` option.
python -m http.server --directory /usr/bin

In machine B, download a file from the web server of machine A.

wget http://<ip>:8000/example.txt

# Download recursively
# -r: Recursive
# -np: No parent
# --reject="index.html*": Not save index.html
# -P: output directory
wget http://<ip>/example_dir -r -np -nH --cut-dirs=1 --reject="index.html*" -P example_dir

Using Netcat

Transfer a File

In machine A, start a listener for receiving a file.

# -l: Listen mode
# -p: Port
nc -lp 4444 > example.txt

In machine B, send a file to machine A.

nc <machineA-ip> 4444 < example.txt

Transfer a Directory

In machine A, start a listener for receiving a directory.

nc -lvnp 4444 > out.tar

In machine B, compress a directory using tar and transfer it.

tar -cf - example/ | nc <machineA-ip> 4444

In machine A, decompress the tar file and get the directory.

tar -xf out.tar

Using Base64

In machine A, encode a file with base64 and copy the encoded Base64 string.

# -w 0: disabe line wrapping
base64 exploit.sh -w 0

In machine B, paste the encoded Base64 string.

echo '123...def==' | base64 -d > exploit.sh