Table of contents
- Upload files to the remote server `scp local file path remote username@remote IP: remote target directory`
- Upload the folder to the remote server `scp -r local folder remote username@remote IP: remote target directory`
- Download files from the remote server `scp remote username@remote IP: remote file path local target directory`
- Download the folder from the remote server `scp -r remote username@remoteIP:remote folder local target directory`
On macOS, you can use
scp
command to upload, download files or folders to a remote server, or get files from a remote server.
scp(Secure Copy Protocol)
is a secure file transfer protocol that securely copies files between local and remote servers.
Note: When using scp, make sure you have the appropriate permissions to access the remote server and local files/folders. In addition, scp uses the SSH protocol by default for secure file transfer, so you need to ensure that the SSH service is running properly on the remote server.
Upload files to remote serverscp 本地文件路径 远程用户名@远程IP:远程目标目录
scp /path/to/local/file user@remote_server_ip:/path/to/remote/directory/
- /path/to/local/file islocal path path.
- user is the username on the remote server.
- remote_server_ip is the IP address or host name of the remote server.
- /path/to/remote/directory/ is thetarget directory on the remote server.
For example, if you want to upload the local file.txt to the /home/user/documents/ directory of the remote server, you can run:
scp file.txt user@remote_server_ip:/home/user/documents/
Upload folder to remote serverscp -r 本地文件夹 远程用户名@远程IP:远程目标目录
scp -r /path/to/local/directory user@remote_server_ip:/path/to/remote/
- Use the -r flag to recursively copy the entire folder and its contents.
For example, if you want to upload the local my_folder folder to the remote server's /home/user/documents/ directory, you can run:
scp -r my_folder user@remote_server_ip:/home/user/documents/
Download files from remote serverscp 远程用户名@远程IP:远程文件路径 本地目标目录
scp user@remote_server_ip:/path/to/remote/file /path/to/local/directory/
- user is the username on the remote server.
- remote_server_ip is the IP address or host name of the remote server.
- /path/to/remote/file is the file path on the remote server.
- /path/to/local/directory/ し本地目标目录.
For example, if you want to download the /home/user/documents/file.txt file from the remote server to the local my_downloads directory, you can run:
scp user@remote_server_ip:/home/user/documents/file.txt my_downloads/
Download folder from remote serverscp -r 远程用户名@远程IP:远程文件夹 本地目标目录
scp -r user@remote_server_ip:/path/to/remote/directory /path/to/local/
- Use the -r flag to recursively copy the entire folder and its contents.
For example, if you want to download the /home/user/documents/my_folder folder from the remote server to the local my_downloads directory, you can run:
scp -r user@remote_server_ip:/home/user/documents/my_folder my_downloads/