리눅스 파일 전송

When working with Linux, it is often necessary to transfer files between different machines. One of the most commonly used methods for file transfer in Linux is using the Bash command line.

In this blog post, we will explore various techniques and commands available in Bash for transferring files between local and remote machines.

1. SCP

SCP (Secure Copy) is a command-line tool used for securely transferring files between a local and a remote machine. It utilizes SSH (Secure Shell) for authentication and data encryption.

To transfer a file from a local machine to a remote server, you can use the following command:

scp [local_file_path] [remote_user]@[remote_server]:[remote_directory]

For example, to transfer a file named “example.txt” from the local machine to the home directory of a remote server:

scp example.txt user@remote_server:~

To transfer a file from a remote server to the local machine, you can use the following command:

scp [remote_user]@[remote_server]:[remote_file_path] [local_directory]

For example, to transfer a file named “example.txt” from the home directory of a remote server to the local machine:

scp user@remote_server:~/example.txt .

2. SFTP

SFTP (SSH File Transfer Protocol) is a secure alternative to FTP for transferring files between machines. It provides a command-line interface for file transfer over an SSH connection.

To initiate an SFTP session, use the following command:

sftp [user]@[server]

Once connected, you can use various commands such as put and get to transfer files to and from the remote server:

put [local_file_path] [remote_directory]   # Upload a file to the remote server
get [remote_file_path] [local_directory]   # Download a file from the remote server

For example, to upload a file named “example.txt” from the local machine to a remote server, use the following command after establishing an SFTP session:

put example.txt /path/to/remote_directory

To download a file named “example.txt” from a remote server to the local machine, use the following command:

get /path/to/remote_file example.txt

3. Rsync

Rsync is a powerful command-line utility for efficiently synchronizing files and directories between two locations. It is widely used for remote backups and mirroring.

To use rsync for file transfer, the basic syntax is as follows:

rsync [options] [source] [destination]

For example, to transfer a directory named “my_files” from the local machine to a remote server:

rsync -avz my_files/ user@remote_server:/path/to/destination_directory

The -a option preserves permissions, timestamps, and other attributes of the files, while the -v option enables verbose output for better visibility. The -z option enables compression during the transfer.

To transfer files from a remote server to the local machine, simply switch the source and destination locations in the rsync command.

Conclusion

In this blog post, we explored various techniques and commands available in Bash for transferring files between local and remote machines in a Linux environment. By using commands like scp, sftp, and rsync, you can securely and efficiently transfer files and directories, making remote collaboration and file management easier.

Remember to choose the method that suits your needs best, based on factors such as security, simplicity, and efficiency. With these powerful file transfer commands at your disposal, handling files in a Linux environment becomes a breeze.