Linux에서 로컬/서버 간에 파일을 전송하는 방법

XShell 또는 MobaXterm과 같은 현재의 많은 원격 연결 도구는 업로드 및 다운로드 기능을 제공합니다. 또한 scp 및 sftp와 같은 일부 Linux 터미널 명령도 이러한 기능을 구현할 수 있어 더욱 유연하고 편리합니다. 전송 요구를 충족할 수 있을 뿐만 아니라 로컬과 서버 간에는 두 개의 원격 서버 간에 파일을 전송할 수도 있습니다. 다음은 scp의 몇 가지 용도입니다.

로컬 파일을 서버에 복사

scp localmachine/path_to_the_file username@server_ip:/path_to_remote_directory

여기서 localmachine/path_to_the_file은 로컬 파일의 경로이고, username@server_ip는 서버의 사용자 이름과 IP이고 그 뒤에 서버의 경로가 옵니다. 명령을 실행하고 서버의 로그인 비밀번호를 입력하면 파일이 server/path_to_remote_directory 위치에 업로드됩니다.

전체 폴더의 내용을 원격 서버에 복사하려면 어떻게 해야 합니까? 또한 매우 간단합니다. -r 매개변수 하나만 추가하면 됩니다.

scp -r localmachine/path_to_the_file username@server_ip:/path_to_remote_directory

서버에서 로컬로 파일 복사

서버에서 파일을 가져오려면 위 명령을 약간만 수정하면 됩니다.

scp username@server_ip:/path_to_remote_directory local_machine/path_to_the_file

같은 방법으로 서버에 폴더를 가져오는 경우 -r 매개변수도 추가합니다.

scp -r username@server_ip:/path_to_remote_directory local_machine/path_to_the_file

서버의 파일을 다른 서버로 복사

서버에 로그인하지 않았고 한 서버에서 다른 서비스로 파일을 복사한다고 가정해 보겠습니다.

scp username@server1_ip:/path_to_the_remote_fileusername@server2_ip:/path_to_destination_direcory/

추천

출처blog.csdn.net/m0_56572447/article/details/131743513