linux下用scp命令在兩個伺服器之間傳輸檔案,利用php_scp函數進行檔案傳輸

來源:互聯網
上載者:User

標籤:scp命令   end   適合   下載   color   username   nec   log   輸入密碼   

在linux下利用scp進行檔案傳輸,

從伺服器下載檔案

scp [email protected]:/path/filename  /path/filename

 

上傳本地檔案到伺服器

scp /path/filename [email protected]:/path/filename

從伺服器下載整個目錄

scp -r [email protected]:remote_dir/  /path/

上傳目錄到伺服器      

scp  -r /dir [email protected]:remote_dir

以上操作在執行時都會提示你輸入密碼,輸入密碼後就會成功執行。

但是這些只適合在操作linux伺服器時使用,如何在程式中執行呢?

在PHP就用到了php_scp_send和php_scp_revc函數

php_scp_send是向另一個伺服器傳輸檔案,php_scp_revc則是下載檔案。

這兩個函數要結合php_ssh2組件使用。

$ssh2 = ssh2_connect($ssh_host, $ssh_port);  //先登陸SSH並串連,具體參照php_ssh2串連//$local_file為本地檔案, $remote_file為遠程檔案//本地傳輸檔案到遠程伺服器$stream=ssh2_scp_send($ssh2, $local_file, $remote_file, 0644);預設許可權為0644,傳回值為bool值,true或false.//從遠程伺服器下載檔案$stream=ssh2_scp_revc($ssh2, $remote_file, $local_file);//傳回值為傳回值為bool值,true或false.

 

linux下用scp命令在兩個伺服器之間傳輸檔案,利用php_scp函數進行檔案傳輸

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.