SFTP从PHP - 未定义的常量CURLOPT_PROTOCOLS和CURLPROTO_SFTP? [英] SFTP from PHP - undefined constant CURLOPT_PROTOCOLS and CURLPROTO_SFTP?

查看:588
本文介绍了SFTP从PHP - 未定义的常量CURLOPT_PROTOCOLS和CURLPROTO_SFTP?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从我的php脚本,我需要能够通过sftp上传csv文件到远程服务器。我按照此问题接受的答案:

From my php script, i need to be able to upload a csv file to a remote server via sftp. I followed the accepted answer from this question:

SFTP from PHP

这是我的代码看起来像

<?php
    error_reporting(E_ALL);
    ini_set('display_errors', 1);

    $ch = curl_init();
    $localfile = 'export-3.csv';
    $fp = fopen($localfile, 'r');

    curl_setopt($ch, CURLOPT_URL, 'sftp://user:pass@ftp.remote.com/'.$localfile);
    curl_setopt($ch, CURLOPT_UPLOAD, 1);
    curl_setopt($ch, CURLOPT_PROTOCOLS, CURLPROTO_SFTP);
    curl_setopt($ch, CURLOPT_INFILE, $fp);
    curl_setopt($ch, CURLOPT_INFILESIZE, filesize($localfile));
    curl_exec ($ch);

    $error_no = curl_errno($ch);
    curl_close ($ch);

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

    echo $error.' '.$error_no;
?>

输出为

Notice: Use of undefined constant CURLOPT_PROTOCOLS - assumed 'CURLOPT_PROTOCOLS' in /home/john/public_html/test/test.php on line 9

Notice: Use of undefined constant CURLPROTO_SFTP - assumed 'CURLPROTO_SFTP' in /home/john/public_html/test/test.php on line 9
File upload error.1

我使用curl libcurl / 7.18.2 OpenSSL / 0.9.8g zlib / 1.2.3.3 libidn / 1.10。当我做了一个sudo apt-get install php5-curl,电脑说我有最新版本。

I am using curl libcurl/7.18.2 OpenSSL/0.9.8g zlib/1.2.3.3 libidn/1.10 . When I did a sudo apt-get install php5-curl, the computer said i had the most recent version.

我做错了什么?我如何sftp从php上传我的文件到远程服务器?

What am I doing wrong? How do i sftp upload my files to a remote server from php?

推荐答案

首先,你安装的libcurl版本似乎

First, your installed libcurl version doesn't seem to be new enough to have the options you try to use.

然后,它也可能是这样的,你的libcurl没有被编译为支持SFTP时,无论谁构建它。 libcurl需要构建使用libssh2为SCP和SFTP传输工作。

Then, it might also be so that your libcurl wasn't compiled to support SFTP when whoever built it. libcurl need to be built to use libssh2 for SCP and SFTP transfers to work.

这篇关于SFTP从PHP - 未定义的常量CURLOPT_PROTOCOLS和CURLPROTO_SFTP?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆