php curl ftp

2018-12-25  本文已影响18人  Fa1se003

上传文件

        $username  = ''; //用户名
        $password  = ''; //密码
        $url       = 'ftps://IP地址/test.html'; //需要上传到服务器的地址+文件名     
        //(ftp or ftps 端口需要注意)
        $local_csv = './uploads/bbb.html'; //待上传的文件地址
        $fp        = fopen($local_csv, 'r');

        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL,$url);
        curl_setopt($curl,CURLOPT_HEADER,0);
        curl_setopt($curl,CURLOPT_RETURNTRANSFER,1);
        curl_setopt($curl,CURLOPT_USERPWD,$username.':'.$password);
        curl_setopt($curl,CURLOPT_PORT,990);
        curl_setopt($curl,CURLOPT_UPLOAD, 1);
        curl_setopt($curl,CURLOPT_INFILE, $fp);
        curl_setopt($curl,CURLOPT_INFILESIZE, filesize($local_csv));
        curl_setopt($curl,CURLOPT_SSL_VERIFYPEER,false);
        curl_setopt($curl,CURLOPT_SSL_VERIFYHOST,false);

        curl_exec($curl);
        $error_no = curl_errno($curl);    
        curl_close($curl);

        if ($error_no === 0) {
            $error = 'File uploaded succesfully.';
        } else {
            $error = 'File upload error.';
        }

       echo  $error;
        
      

       

        $username  =''; //用户名
        $password  =''; //密码
        $url       ='ftps://IP地址/test.html'; //待下载的文件地址  
        $local_csv = './uploads/local_test.html';//保存到本地的文件地址
        $fp        = fopen($local_csv, 'w');
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL,$url);
        curl_setopt($curl,CURLOPT_HEADER,0);
        curl_setopt($curl,CURLOPT_USERPWD,$username.':'.$password);
        curl_setopt($curl,CURLOPT_PORT,990);        
        curl_setopt($curl,CURLOPT_SSL_VERIFYPEER,false);
        curl_setopt($curl,CURLOPT_SSL_VERIFYHOST,false);
        curl_setopt($curl,CURLOPT_FILE,$fp);

        curl_exec($curl);
        $error_no = curl_errno($curl);    
        curl_close($curl);

        if ($error_no === 0) {
            $error = 'File download succesfully.';
        } else {
            $error = 'File download error.';
        }

        echo  $error;
上一篇下一篇

猜你喜欢

热点阅读