Skip to content

Commit

Permalink
Create ftp02.php
Browse files Browse the repository at this point in the history
  • Loading branch information
miscsstake committed Sep 20, 2014
1 parent b356aa0 commit 0d0e191
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions ftp02.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php
/**
* 慕课网视频教学
* 代码实例-PHP-cURL实战
* 实例描述:把本地文件上传到FTP服务器上
*/
$curlobj = curl_init();
$localfile = 'ftp01.php';
$fp = fopen($localfile, 'r');

curl_setopt($curlobj, CURLOPT_URL, "ftp://192.168.1.100/ftp01_uploaded.php");
curl_setopt($curlobj, CURLOPT_HEADER, 0);
curl_setopt($curlobj, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curlobj, CURLOPT_TIMEOUT, 300); // times out after 300s
curl_setopt($curlobj, CURLOPT_USERPWD, "peter.zhou:123456");//FTP用户名:密码

curl_setopt($curlobj, CURLOPT_UPLOAD, 1);
curl_setopt($curlobj, CURLOPT_INFILE, $fp);
curl_setopt($curlobj, CURLOPT_INFILESIZE, filesize($localfile));
$rtn = curl_exec($curlobj);
fclose($fp);
if(!curl_errno($curlobj)){
echo "Uploaded successfully.";
} else {
echo 'Curl error: ' . curl_error($curlobj);
}
curl_close($curlobj);
?>

0 comments on commit 0d0e191

Please sign in to comment.