Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/265.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php cURL-如何将PDF文件发送到SFTP服务器_Php_Pdf_Curl - Fatal编程技术网

Php cURL-如何将PDF文件发送到SFTP服务器

Php cURL-如何将PDF文件发送到SFTP服务器,php,pdf,curl,Php,Pdf,Curl,我正在尝试使用cURL将pdf文件发送到远程sftp服务器。首先,我发送了一个csv文件,该文件已成功发送到服务器,内容正确。 但是现在我正在尝试发送一个pdf文件,我确实发送了,但是大小是0 kb $ch = curl_init('sftp://' . $sftpServer . ':' . $sftpPort . $sftpRemoteDir . '/' . basename($dataFile)); $fh = fopen($dataFile, 'r');

我正在尝试使用
cURL
pdf
文件发送到远程sftp服务器。首先,我发送了一个
csv
文件,该文件已成功发送到服务器,内容正确。 但是现在我正在尝试发送一个
pdf
文件,我确实发送了,但是大小是
0 kb

$ch = curl_init('sftp://' . $sftpServer . ':' . $sftpPort . $sftpRemoteDir . '/' . basename($dataFile));

            $fh = fopen($dataFile, 'r');

            if ($dataFile) {
                curl_setopt($ch, CURLOPT_USERPWD, $sftpUsername . ':' . $sftpPassword);
                curl_setopt($ch, CURLOPT_UPLOAD, true);
                curl_setopt($ch, CURLOPT_PROTOCOLS, CURLPROTO_SFTP);
                curl_setopt($ch, CURLOPT_INFILE, $fh);
                curl_setopt($ch, CURLOPT_INFILESIZE, filesize($fh));
                curl_setopt($ch, CURLOPT_VERBOSE, true);

                $verbose = fopen('php://temp', 'w+');
                curl_setopt($ch, CURLOPT_STDERR, $verbose);

                $response = curl_exec($ch);
                $error = curl_error($ch);
                curl_close($ch);

                if ($response) {
                    echo "Success";
                } else {
                    echo "Failure";
                    rewind($verbose);
                    $verboseLog = stream_get_contents($verbose);
                    echo "Verbose information:\n" . $verboseLog . "\n";
                }
            } 

我了解到使用
fopen
无法打开
pdf
文件。我不确定是否需要另一个类似于
fopen
的功能来上传大小和内容正确的
pdf
文件。有什么可能的解决方案吗?

您是在问如何使用curl或php的libcurl api通过sftp上传文件?因为您的问题似乎暗示您希望使用curl来实现,但您的代码示例试图使用php/libcurl@hanshenrik是的,使用libcurl@hanshenrik有溶液或样品吗?谢谢