Transfer files between two computers
File Transfer Between Linux Systems
1. Netcat + Tar (Fast but Less Secure)
To send a directory:
- On the sender:
tar -cz . | nc -q 10 -l -p 45454
- On the receiver:
nc -w 10 $REMOTE_HOST 45454 | tar -xz
- Replace
$REMOTE_HOST
with the sender’s IP address or hostname. - You can change the port
45454
to another port of your choice.
- Replace
2. Copying Files with SCP
Commands for file transfer using scp
:
- To transfer a file:
scp <file> <username>@<IP or hostname>:<Destination>
- To transfer directories recursively:
scp -r <local_path> <username>@<server>:(remote_path) scp -r <username>@<server>:(remote_path) <local_path>
3. Using SSHFS (Secure and Convenient)
Installation:
On the client:
sudo apt-get install sshfs
Mounting a Remote File System:
sshfs -o transform_symlinks -ofollow_symlinks user@hostname:/remote/path /local/mountpoint
Example:
sshfs -o cache=yes,allow_other user@192.168.1.200:/home/user/code /home/user/code
Unmounting:
sudo umount /local/mountpoint
Note: For sharing with multiple users, consider using NFS. Refer to this NFS configuration tutorial for details.
File Transfer Between Windows and Linux
1. Samba Server
Samba is a convenient tool for sharing files between Windows and Linux, similar to NFS.
Setting Up Samba on Linux:
- Install Samba:
sudo apt update sudo apt install samba
- Create a shared directory:
mkdir /home/<username>/sambashare/
- Edit the Samba configuration file:
sudo vim /etc/samba/smb.conf
Add the following lines:
[sambashare] comment = Samba on Ubuntu path = /home/<username>/sambashare read only = no browsable = yes
- Restart Samba:
sudo service smbd restart
- Add a Samba user and set a password:
sudo smbpasswd -a <username>
Note: The Samba username must match a system account for it to work.
Accessing Samba Shares from Windows:
- Open File Explorer on Windows.
- Enter the following in the address bar:
\\<ip-address>\sambashare
Replace
<ip-address>
with the Linux machine’s IP address.
This guide provides efficient methods for secure and convenient file sharing across Linux and Windows systems.
Comments