Php 使用Dropbox API将文件直接传输到远程FTP服务器,而无需下载中间文件

Php 使用Dropbox API将文件直接传输到远程FTP服务器,而无需下载中间文件,php,ftp,dropbox,data-stream,Php,Ftp,Dropbox,Data Stream,我在Dropbox上有大量的设计文件(高达500 MB),我正在构建一个工具,在我们基于PHP的在线项目管理程序中,以编程方式将单个文件传输到供应商的FTP服务器。由于文件大小的原因,我不想将文件下载到服务器,然后将该文件上载到FTP服务器,因为速度和存储空间都有问题 我可以使用以下Dropbox API调用: getFile( string $path, resource $outStream, string|null $rev = null ) Downloads a file from D

我在Dropbox上有大量的设计文件(高达500 MB),我正在构建一个工具,在我们基于PHP的在线项目管理程序中,以编程方式将单个文件传输到供应商的FTP服务器。由于文件大小的原因,我不想将文件下载到服务器,然后将该文件上载到FTP服务器,因为速度和存储空间都有问题

我可以使用以下Dropbox API调用:

getFile( string $path, resource $outStream, string|null $rev = null )
Downloads a file from Dropbox. The file's contents are written to the given $outStream and the file's metadata is returned.
我猜我可以使用以下PHP命令:

ftp_fput ( resource $ftp_stream , string $remote_file , resource $handle , int $mode [, int $startpos = 0 ] )
Uploads the data from a file pointer to a remote file on the FTP server.
我没有任何关于文件数据流的经验,所以我不知道如何将两者连接起来。经过几个小时的在线搜索,我想我应该试着在这里问一下


如何将getFile的$outstream资源与ftp\u fput的$ftp\u stream资源连接起来?

花了半天的时间进行试验,最终使其正常工作。解决方案包括使用PHP data://scheme在内存中创建一个流,然后倒带该流以将其发送到FTP服务器。以下是它的要点:

// open an FTP connection
$ftp_connection = ftp_connect('ftp.example.com');
ftp_login($ftp_connection,'username','password');

// get the file mime type from Dropbox, to create the correct data stream type
$metadata = $dopbox->getMetadata($file) // $dropbox is authenticated connection to Dropbox Core API; $file is a complete file path in Dropbox
$mime_type = $metadata['mime_type'];

// now open a data stream of that mime type
// for example, for a jpeg file this would be "data://image/jpeg"
$stream = fopen('data://' .mime_type . ',','w+'); // w+ allows both writing and reading
$dropbox->getFile($file,$stream); // loads the file into the data stream
rewind($stream)
ftp_fput($ftp_connection,$remote_filename,$stream,FTP_BINARY); // send the stream to the ftp server

// now close everything
fclose($stream);
ftp_close($ftp_connection);

我还没试过这个,但也许stream\u copy\u\u to\u stream可以完成这个任务@格雷格,好主意,但没用。然而,你确实给我指出了正确的方向。我很感激,这对我没用。我收到错误:PHP致命错误:未捕获异常“InvalidArgumentException”,消息“outStream”的类型不正确;应为资源,获取布尔值