Home  >  Article  >  Backend Development  >  PHP method to implement FTP file transfer based on curl

PHP method to implement FTP file transfer based on curl

墨辰丷
墨辰丷Original
2018-06-08 09:52:532040browse

This article mainly introduces the method of FTP file transfer in PHP based on curl. Interested friends can refer to it. I hope it will be helpful to everyone.

The details are as follows:

<?php
function upload($dir,$src,$dest)
{
  $ch = curl_init();
  $fp = fopen($src, &#39;r&#39;);
  curl_setopt($ch, CURLOPT_URL, &#39;ftp://user:pwd@host/interpretation/&#39;.$dir .&#39;/&#39;. $dest);
  curl_setopt($ch, CURLOPT_UPLOAD, 1);
  curl_setopt($ch, CURLOPT_INFILE, $fp);
  curl_setopt($ch, CURLOPT_INFILESIZE, filesize($src));
  curl_exec ($ch);
  $error_no = curl_errno($ch);
  curl_close ($ch);
  if ($error_no != 0)
  {
     return 0;
  }else{
   return 1;
  }
} 
upload("images","s.py","aaa.py");
?>

Summary: The above is the entire content of this article, I hope it will be helpful to everyone's study.

Related recommendations:

How to operate the database with php combined with session

How to localize remote images in php

PHP method of accepting files and getting suffix names

The above is the detailed content of PHP method to implement FTP file transfer based on curl. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn