<?php
$localfile = 'test1.txt';
$fp = fopen ($localfile, "r") or die('Cannot open textfile');
$connection = ssh2_connect('sftp_server_path/folder',22);
ssh2_auth_password($connection, 'username', 'password');
$sftp = ssh2_sftp($connection) or die ("Cannot connect to server");
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"sftp_server_path/folder/test1.txt");
curl_setopt($ch, CURLOPT_USERPWD, "username:password");
curl_setopt($ch, CURLOPT_UPLOAD, 1);
curl_setopt($ch, CURLOPT_INFILE, $fp);
if(curl_exec($ch)){
echo 'File was successfully transferred using SFTP';
}else{
echo 'File was unable to be transferred using SFTP';
}
?>
我有上面的代碼連接並傳輸到sftp服務器,我運行此代碼我得到消息「文件已成功傳輸使用SFTP」。但是當我在sftp服務器中看到文件夾結構時,我無法在sftp服務器上看到我的傳輸文件。我到底要做什麼?如何從sftp服務器訪問文件?
這意味着我的文件夾權限?其777. – user1122910 2012-03-20 06:56:10