我对此很陌生 - 我正在尝试使用以下 2 个类将文件上传到 FTP,但是它一直无法上传
//class.FTP.php class
CONSTRUCTOR INPUT:
1. server name
2. user name
3. user password
4. destination directory
*/
class ftp
{
var $ftp_server;
var $ftp_user_name;
var $ftp_user_pass;
var $dst_dir;
var $conn_id;
var $login_result;
function ftp($ftp_server,$ftp_user_name,$ftp_user_pass,$dst_dir)
{
if ($ftp_server!="" && $ftp_user_name!="" && $ftp_user_pass!="" && $dst_dir!="") {
$this->ftp_server = $ftp_server;
$this->ftp_user_name = $ftp_user_name;
$this->ftp_user_pass = $ftp_user_pass;
$this->dst_dir = $dst_dir;
}
else
return false; // bad parametrs
if (!$this->connect() || !$this->setdir())
return false; // bad connect or no exist directory
else return true; // ALL OK
}
/* FTP connect */
function connect()
{
$this->conn_id = @ftp_connect($this->ftp_server);
$this->login_result = @ftp_login($this->conn_id, $this->ftp_user_name, $this->ftp_user_pass);
if ((!$this->conn_id) || (!$this->login_result))
return false;
else return true;
}
/* Set Directory */
function setdir()
{
if (!@ftp_chdir($this->conn_id, $this->dst_dir))
return false;
else return true;
}
/*Send file */
INPUT:
$remote_file -> file for send
$file -> read file
$mode -> "FTP_BINARY","FTP_ASCII",...
*/
function sendfile($remote_file, $file, $mode="FTP_BINARY")
{
if (@ftp_put($this->conn_id, $remote_file, $file, $mode))
return true;
else
return false;
}
} //end class
//Test class
//$path = 1852 - Future Father-in-law on your birthday.mp3
//$dst_dir = /htdocs/site2/telemessages/en/birthdays/Child/
$send_file = $path; // file for sending
$remote_file = $path; // destination file
$ftp_server = "213.171.193.5"; // server name
$ftp_user_name = "************"; // user name
$ftp_user_pass = "*************"; // password
$dst_dir = "/htdocs/site2/telemessages/en/".$_SESSION['dir']; // destination directory ( www/upload/ )
//include class
include ('class.FTP.php');
//class constructor
$ftp = new ftp($ftp_server,$ftp_user_name,$ftp_user_pass,$dst_dir);
// sending any file
// FTP_ASCII or FTP_BINARY
$err = $ftp->sendfile($remote_file, $send_file, "FTP_BINARY");
echo "TEST";
if (!$err) echo "No transfer !";
else echo "Transfer OK.";
我不断收到消息“没有转移!” 而且我也不确定分配给 $remote_file 变量的含义。
提前致谢!