2014-03-04 97 views
0

我是PHP新手。我有我的服務器的以下細節。現在我需要使用SFTP從本地主機應用程序上傳(或移動).sql文件到服務器。我嘗試了很多,最終失敗了。如何使用sftp將文件傳輸到服務器?

  • 主機名
  • 端口號
  • 用戶名
  • 密碼
  • 位置

請人給我一個簡單的例子來連接SFTP連接到我的服務器上傳文件。

+0

http://php.net/ssh2_sftp – Quentin

回答

1

如果你只是想傳輸一個文件,並不在乎使用scpsftp,那麼我會鼓勵你使用scp。又來了一個基本的例子(taken from the PHP manual):

$connection = ssh2_connect('www.example.com', 22); 
if($connection === FALSE) { 
    die('Failed to connect'); 
} 

$state = ssh2_auth_password($connection, 'username', 'password'); 
if($state === FALSE) { 
    die('Failed to authenticate'); 
} 

$state = ssh2_scp_send($connection, '/local/filename', '/remote/filename', 0644); 
if($state === FALSE) { 
    die('Failed to transfer the file'); 
} 
+0

非常感謝你的回答。如何捕捉錯誤? – JaiSat

+0

你只能看看返回值。檢查我的更新 – hek2mgl

相關問題