- 16 Views
- 27/07/2025
SCP Folder Transfer to Remote Server
To transfer a folder to another server using scp (secure copy), follow these steps:
1. Basic Syntax:
- -r: Recursively copies the entire folder, including its contents and subdirectories.
- /path/to/local/folder: Path to the folder on your local machine.
- username: The user account on the remote server.
- remote_host: The IP address or hostname of the remote server (e.g., 192.168.1.100 or example.com).
- /path/to/remote/destination: Where the folder will be copied on the remote server.
2. Example:
To transfer a folder named my_folder from your local machine to /home/user/destination on a remote server:
3. Key Points:
- SSH Access: Ensure you have SSH access to the remote server and the correct credentials.
- Permissions: Verify you have read permissions for the local folder and write permissions for the remote destination.
- Port Specification: If the remote server uses a non-standard SSH port (not 22), add -P port_number:
- Preserve File Attributes: Use -p to preserve file modification times and permissions:
4. Authentication:
- If using a password, you’ll be prompted to enter it.
- For key-based authentication, ensure your SSH key is set up (e.g., ~/.ssh/id_rsa) and added to the remote server’s ~/.ssh/authorized_keys.
5. Common Issues:
- Connection Refused: Check if the SSH service is running on the remote server and the port is open.
- Permission Denied: Verify the user has access to the destination path and the SSH key/password is correct.
- Folder Overwrite: If the destination folder exists, scp will copy the folder inside it. To overwrite, remove the existing folder on the remote server first.
