9月 192017
 

首先, 验证php的curl模块是否支持sftp,验证方法:

有结果就是支持,否则就是不支持

 

curl 实现http文件上传的逻辑大致如下:

curl 实现sftp文件上传的方式是否可以如法炮制?

原以为修改下url地址(如: sftp://username:password@phpor.net/test.txt ) 就可以搞定,实际不然:(毕竟POSTFILDS 的内容就不太好解释),正确的姿势如下:

注意:

  1. 其中的 curl_setopt($s, CURLOPT_UPLOAD, true);  或 curl_setopt($s, CURLOPT_PUT, true); 是要有的,且: 换做curl_setopt($s, CURLOPT_PUT, true);  是不行的
  2. CURLOPT_INFILE 是一个文件流,不能是文件名

有时候,ssh2模块使用起来更加方便,但是真的没有的时候,curl也不算太复杂;另外,ssh2 附带注册了一个stream wrapper, 当安装了ssh2模块时,你甚至可以 fopen(“sftp://….”)

 

 Posted by at 下午 3:25

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">

(required)

(required)

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据