$filepath = __DIR__./d.txt; $basename = pathInfo($filepath, PATHINFO_BASENAME); $filesize = fileSize($filepath); $fh = fopen($filepath, r); #sftp协议, url是服务器全路径,且带文件名 $url = sftp://192.168.1.2/data/temp/.$basename; // create curl resource $ch = curl_init(); // set url curl_setopt($ch, CURLOPT_URL, $url); //return the transfer as a string curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_USERPWD, root:123456); #ssh的 服务器的用户名和密码 curl_setopt($ch, CURLOPT_UPLOAD, true); # curl_setopt($ch, CURLOPT_INFILE, $fh ); #文件句柄 curl_setopt($ch, CURLOPT_INFILESIZE, $filesize); #文件大小 $output = curl_exec($ch); $message = curl_errno($ch) === CURLE_OK ? success : failure; echo $message; curl_close($ch);
文章存档
热门标签
使用curl上传文件至服务器
上一篇:curl参数总结 下一篇:TCP三次握手和四次挥手
最新评论查看所有评论>>