Operating System - HP-UX
1822194 Members
3896 Online
109640 Solutions
New Discussion юеВ

Re: scp file with a specific port

 
haeman
Frequent Advisor

scp file with a specific port

I want to use scp to copy file from server A to server B , if I want the copying is via a specific port ( not use the default port ) , can advise what can i do ? thx
11 REPLIES 11
Kenan Erdey
Honored Contributor

Re: scp file with a specific port

Hi,

you can use scp -P but on the other side ssh should listen that port number. so you should do appropirate changes.
Computers have lots of memory but no imagination
Sandeep_Chaudhary
Trusted Contributor

Re: scp file with a specific port

u have to use -P option with 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 file in
rcp(1).
Th ereceiver should receive on specified port no
Steven E. Protter
Exalted Contributor

Re: scp file with a specific port

Shalom,

scp -p (permissions) -P

example
scp -p file.mine -P 22040 hostname:/destination

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Suraj K Sankari
Honored Contributor

Re: scp file with a specific port

Hi,
See this 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 file inrcp(1).

Suraj
haeman
Frequent Advisor

Re: scp file with a specific port

thx reply ,

when use scp -p file.mine -P 22040 hostname:/destination

it pop

-P: No such file or directory
22040: No such file or directory

what is wrong ? thx
H.Merijn Brand (procura
Honored Contributor

Re: scp file with a specific port

Do you have a very old or broken scp? scp's usage message should show the -P (capital P) usage

$ scp
usage: scp [-1246BCpqrv] [-c cipher] [-F ssh_config] [-i identity_file]
[-l limit] [-o ssh_option] [-P port] [-S program]
[[user@]host1:]file1 ... [[user@]host2:]file2
$ ssh -V
OpenSSH_4.7p1, OpenSSL 0.9.8g 19 Oct 2007

Enjoy, have FUN! H.Merijn
Enjoy, Have FUN! H.Merijn

Re: scp file with a specific port

Provide me the output of below command
#ssh -v

update the ssh pkg to get -P option .
Suraj K Sankari
Honored Contributor

Re: scp file with a specific port

Hi,

Try like this
scp file.mine -P 22040 hostname:/destination

suraj
Matti_Kurkela
Honored Contributor

Re: scp file with a specific port

As the usage line indicates, you must specify the options (including the -P option) _before_ specifying any files to copy.

i.e. the correct order of parameters is:

scp -P 22040 file.mine hostname:/destination

Or if you want to use the -p option to preserve the file times and permissions:

scp -p -P 22040 file.mine hostname:/destination

MK
MK
Ralph Grothe
Honored Contributor

Re: scp file with a specific port

For this to work the other end's sshd needs to listen to that non-standard port.
But one reason why you asked might be that you would like SSH forward you a remote sshd's standard port to some local unused port because both hosts aren't allowed to communicate directly due to some firewall?
If you have an interim hop host that is allowed to ssh to the remote host, and if you have someone as an account thereon then you could scp via this hop through a tunnel.

Assuming port 2222 isn't in use on localhost you could build the tunnel like this
(note that the sleep has the advantage that you don't need to kill the tunnel when you're done (often forgotten) because it will shut down after 10 minutes).

$ ssh -NL2222:not_directly_reachable_host:22 someone@hop_host sleep 600

Once the tunnel is errected
(check by "netstat -anfinet|grep 2222.*LISTEN)
you can use the locally forwarded port 2222 and copy seemingly from localhost (remember that you need to supply the password of someone on remote host; also note that picking /dev/null as your local user's known_hosts file will prevent you from wrong host keys being saved for localhost)

$ scp -P 2222 -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no someone@localhost:/some/file/you/want/to.get /some/local/target
Madness, thy name is system administration
Ralph Grothe
Honored Contributor

Re: scp file with a specific port

There's a typo in my SSH tunnel start command.
Of course, as you will have noticed, instead of
"$ ssh -NL..." it has to be "$ ssh -fL..."
-N would contradict the sleep command.
Madness, thy name is system administration