如何通过ssh将文件从本地复制到远程

ang*_*iwi -2 ssh scp

这是如何向服务器发出嘘声

ssh -p 2222 thatilike@192.185.21.105

我想将文件复制logo.pngpublic_html服务器上的文件夹

这是我试过的

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

不知道为什么不工作

ale*_*xus 5

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.
Run Code Online (Sandbox Code Playgroud)

更正的语法:

scp -P 2222 ./logo.png thatilike@192.185.21.105:/public_html/
Run Code Online (Sandbox Code Playgroud)

例子:

$ touch ./logo.png
$ scp -P XXXXX ./logo.png XXX@XXX.XXX:/tmp/
logo.png                                                             100%    0     0.0KB/s   00:00    
$ 
Run Code Online (Sandbox Code Playgroud)

要检查连接性(通过ssh)和目标目录是否存在,请执行以下操作。

$ ssh -p XXXXX XXX@XXX.XXX 'if [ -d /tmp/ ] ; then ls -ld /tmp/ ; fi'
drwxrwxrwt  21 root  wheel  31232 Mar  3 23:04 /tmp/
$ 
Run Code Online (Sandbox Code Playgroud)