首页 > 开发 > PHP > 正文

用PHP写FTP文件上传

2024-05-04 22:53:33
字体:
来源:转载
供稿:网友
国内最大的酷站演示中心!

$ftp_server = "*.*.*.*";
$ftp_user = "lu";
$ftp_pass = "love you";

// set up a connection or die
$conn_id = ftp_connect($ftp_server) or die("couldn't connect to $ftp_server");

$login_result = ftp_login($conn_id, $ftp_user, $ftp_pass);

if ((!$conn_id) || (!$login_result)) {
        echo "ftp connection has failed!";
        echo "attempted to connect to $ftp_server for user $ftp_user_name";
        exit;
    } else {
        echo "connected to $ftp_server, for user $ftp_user_name";
    }

// try to login
 $filename=date('ymd').".xml";
 $source_file="/usr/local/ivr/sendwireless/xml/data/".$filename;  //源地址
 echo $source_file;
 $destination_file="/itc/admin/logstat/ftplog/".$filename;  //目标地址
 $upload = ftp_put($conn_id, $destination_file, $source_file, ftp_binary) or die("couldn't connect to $ftp_server");
 ftp_quit($conn_id);

 if (!$upload) {
        echo "ftp upload has failed!";
    } else {
        echo "uploaded $source_file to $ftp_server as $destination_file";
    }
ftp_close($conn_id);

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表