There are multiple ways to share files through SSH:
SCP is a straightforward method for copying files between hosts on a network.
scp [options] [source] [destination]
Copying a file from local to remote:
scp /path/to/localfile username@remotehost:/path/to/remotefile
Copying a file from remote to local:
scp username@remotehost:/path/to/remotefile /path/to/localfile
Copying a directory recursively from local to remote:
scp -r /path/to/localdirectory username@remotehost:/path/to/remotedirectory
Copying a directory recursively from remote to local:
scp -r username@remotehost:/path/to/remotedirectory /path/to/localdirectory
SFTP is an interactive file transfer program that uses the SSH protocol. It is useful for transferring files and navigating remote directories.
sftp username@remotehost
Listing files in the remote directory:
ls
Change directory on remote server:
cd /path/to/directory
Upload a file to the remote server:
put localfile
Download a file from the remote server:
get remotefile
Upload a directory recursively:
put -r localdirectory
Download a directory recursively:
get -r remotedirectory
RSYNC is a versatile tool for syncing files and directories between local and remote systems. It is efficient and can resume transfers.
rsync [options] [source] [destination]
Sync a local directory with a remote directory:
rsync -avz /path/to/localdirectory username@remotehost:/path/to/remotedirectory
Sync a remote directory with a local directory:
rsync -avz username@remotehost:/path/to/remotedirectory /path/to/localdirectory
Exclude files or directories from being synced:
rsync -avz --exclude='*.tmp' /path/to/localdirectory username@remotehost:/path/to/remotedirectory
SSHFS allows you to mount a remote filesystem over SSH, so you can interact with remote files as if they were local.
On Debian/Ubuntu:
sudo apt-get install sshfs
On Red Hat/CentOS:
sudo yum install sshfs
sshfs username@remotehost:/path/to/remotedirectory /path/to/localmountpoint
fusermount -u /path/to/localmountpoint