SCP commands

When using scp (secure copy) to transfer files, you can specify a port number using the -P option (note that it is a capital “P”). Here’s how you do it:

 

SCP Command with a Specific Port

 

scp -P [port_number] [source] [destination]

 

• -P [port_number]: Specifies the port number to use for the connection.

• [source]: The file or directory you want to copy.

• [destination]: The destination where the file or directory should be copied.

 

Example Usage

 

1. Copying a File from Local to Remote Server

• You have a file named myfile.txt that you want to copy to a remote server on port 2222:

 

scp -P 2222 myfile.txt user@remote_host:/remote/directory/

 

Explanation:

• -P 2222: Connects to port 2222 on the remote server.

• user@remote_host: Specifies the username and hostname or IP address of the remote server.

• /remote/directory/: Path on the remote server where you want to place the file.

 

2. Copying a File from Remote Server to Local Machine

• Copying a file named myfile.txt from a remote server on port 2222 to your local machine:

 

scp -P 2222 user@remote_host:/remote/directory/myfile.txt /local/directory/

 

Explanation:

• Connects to port 2222 of remote_host and copies myfile.txt to /local/directory/.

 

Notes

 

• Always use a capital -P for specifying the port in scp. (The lowercase -p is used for preserving file attributes like modification times.)

• The port number is necessary if the remote SSH server is running on a non-standard port (i.e., not the default port 22).

 

Using -P ensures that scp uses the specified port, allowing you to connect even if your server has SSH configured on a custom port.


scp -P 558 -r /Volumes/TBPirate/-SpiffyProjects-/spiffynasty/BACKUP/oct2024/* shjeel@192.168.0.00:/volume1/Web/wordpress/wp-content/backups-dup-pro/imports
Scroll to Top