CURL FTP上传

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<?php
//作者: 大药瓶子
$ch = curl_init();
$file='install.php';
$fp = fopen($file, 'r');
curl_setopt($ch, CURLOPT_URL, 'ftp://14.152.85.84/wwwroot/'.$file);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_USERPWD, "eooo:xuchangyu");//FTP用户名:密码
curl_setopt($ch, CURLOPT_UPLOAD,1);
curl_setopt($ch, CURLOPT_INFILE,$fp);
curl_setopt($ch, CURLOPT_INFILESIZE,filesize($file));
curl_exec($ch);
$error_no = curl_errno($ch);
curl_close ($ch);
fclose($fp);
if ($error_no != 0)
{
echo '0';
}else{
echo '1';
}
?>

实例2

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?php

set_time_limit(0);

//页面地址

$url2 = 'http://uploadv2.zhuanmi.net:443/web/upload.do?userid=1381723&maxsize=2147483648&folderid=12233121&key=47b9104f702e3957c7fbc07866ab258e';//这里是要上传的地址

$name =$_GET["name"];

//$name = urlencode($name);

$post = array(

"excel"=>"@$name",//这里是要上传的文件,key与后台处理文件对应

);

//访问页面2

$ch2=curl_init($url2);

curl_setopt($ch2, 'Mozilla/5.0 (Linux; U; Android 2.3; en-us) AppleWebKit/999 (KHTML, like Gecko) Safari/999.9');

curl_setopt($ch2, CURLOPT_POST, 1);

curl_setopt($ch2, CURLOPT_POSTFIELDS, $post);

curl_setopt($ch2, CURLOPT_RETURNTRANSFER, true);

curl_setopt($ch2, CURLOPT_REFERER, null);

$content2 = curl_exec($ch2);

curl_close($ch2);

echo $content2;



$result = unlink($name);

?>
0%