this is how to shh to server

ssh -p 2222 thatilike@192.185.21.105

I want to copy file logo.png to public_html folder on server

This is what I tried

scp ./logo.png -p 2222 thatilike@192.185.21.105:/public_html/

Don't know why not work

up vote 5 down vote accepted

per 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 file in rcp(1).

 -p      Preserves modification times, access times, and modes from the original file.

corrected syntax:

scp -P 2222 ./logo.png thatilike@192.185.21.105:/public_html/

example:

$ touch ./logo.png
$ scp -P XXXXX ./logo.png XXX@XXX.XXX:/tmp/
logo.png                                                             100%    0     0.0KB/s   00:00    
$ 

to check connectivity (via ssh) and target directory exist do following.

$ ssh -p XXXXX XXX@XXX.XXX 'if [ -d /tmp/ ] ; then ls -ld /tmp/ ; fi'
drwxrwxrwt  21 root  wheel  31232 Mar  3 23:04 /tmp/
$ 
  • I just your command. After enter, I wait for a while and I got this message ssh: connect to host 192.185.21.105 port 22: Operation timed out lost connection – angry kiwi Mar 3 '17 at 18:07
  • @angrykiwi I just revised it, try it again (assuming your host is up and source file and destination directory exists, it should work) – alexus Mar 3 '17 at 18:09
  • With updated commnad I got this message scp: /public_html/: Is a directory – angry kiwi Mar 3 '17 at 19:03
  • @angrykiwi if use my line exactly, it'll work. – alexus Mar 3 '17 at 19:37
  • I don't know why it doesn't, I made video, youtu.be/jwRrwkXs8Xw – angry kiwi Mar 4 '17 at 2:41

Your command line doesn't specify the port number correctly.

As seen in the scp man page:

     -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.

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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