According to IOS documentation*, you can initialize an SSH session from a switch/router and indicate the remote port to connect to, ex. ssh -p 22222

SCP, however, doesn't seem to have that flexibility. copy doesn't allow any connection-specific flags, nor is there an option to add any after entering the scp address. This is a bit of an inconvenience when the remote host doesn't use the default SSH port.

I'm 99% certain that this is a "well that's obviously your answer" situation, but it's worth a shot. Are there any "deeper" commands that "unlock" the ability to specify the remote host's SCP/SSH port?


To help clarify, I'm referring to invoking scp from the switch to the remote host. So on the switch/router you would be typing copy scp:remote local or copy local scp:remote

*(Should it matter, I'm mostly using 2960, 3750(X), 3850, 4506/4507, and 6509)

  • 2
    I strongly recommend against using non-standard ssh ports, this does not do anything in the way of security and makes your devices vulnerable to other types of attacks. Save yourself some time and change it back to default. Aug 13, 2016 at 0:59
  • @brian-winning-jr Unfortunately it's not my server (it belongs to our engineering team) but I agree that changing the ports does nothing to "improve" security. The newest member of the engineering team is pushing to change it back to default so that scp will work properly when trying to transfer from IOS CLI Aug 15, 2016 at 18:55
  • Did any answer help you? If so, you should accept the answer so that the question doesn't keep popping up forever, looking for an answer. Alternatively, you could provide and accept your own answer.
    – Ron Maupin
    Aug 11, 2017 at 15:09

2 Answers 2


This wasn’t possible to perform from the switch/router

  • It should be possible to use SCP from a remote host to transfer files between the switch and whatever host the file needs to go to using: scp -3 ${SWITCH_HOSTNAME}:file ${REMOTE_HOST}:file May 30, 2018 at 21:08
  • @charles-d-pantoga this would be true if the switch had ip scp server enable, but when I asked this question the standard configuration for switches at this place of employment did not enable this. So it was never possible to initiate an SCP session from a remote host. We could only do so from the switch. Jan 6, 2022 at 19:59
  • Why are you replying to me 4 years later? Your question was "How do I specify the remote port of an SCP connection", not "How do I specify a remote port for SCP on a machine that doesn't allow SCP connections"... smh Apr 7, 2022 at 16:17
  • Because I was closing the question and specifying why your answer was not chosen. Again, as the question states, the user would be on the switch/router to run the SCP command, so Cisco IOS would need to support specifying a remote port, which it does not. Apr 7, 2022 at 22:14

Yes, it is possible to specify a remote port. On your the localhost you can use the SSH config. You can also do it like this:

$ man scp
    -P port
         Specifies the port to connect to on the remote host.  Note that
         this option is written with a capital `P', because -p is
         already reserved for preserving the times and modes of the
$ scp -P 6969 /path/to/files.tgz user@remotehost:/path/to/drop/file/at

I would suggest using rsync over scp though, and you can specify the port with rsync as well:

   rsync [OPTION]... SRC [SRC]... rsync://[USER@]HOST[:PORT]/DEST
   rsync [OPTION]... rsync://[USER@]HOST[:PORT]/SRC [DEST]
  • 1
    The question is about SCP on IOS, not some other OS.
    – Zac67
    Apr 8, 2022 at 5:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.