php - 使用 php cURL 在 ftp 站点上移动文件

标签 php curl ftp

我需要在使用 php cURL 下载后重命名文件。

这是我所拥有的:

    $localFile = fopen($fileName, 'w');

    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($curl, CURLOPT_FILE, $localFile);
    curl_setopt($curl, CURLOPT_USERPWD, "$ftpUsername:$ftpPassword");
    curl_setopt($curl, CURLOPT_POSTQUOTE, array("RNFR $remoteFile", "RNTO $remoteFile.downloaded"));

    curl_exec($curl) === false) {
        throw new Exception(curl_error($curl));
    }

如果我删除 CURLOPT_POSTQUOTE 部分,文件下载正常。我还尝试了后引号数组的几种不同组合:

    curl_setopt($curl, CURLOPT_POSTQUOTE, array("RNFR $remoteFile RNTO $remoteFile.downloaded"));
    curl_setopt($curl, CURLOPT_POSTQUOTE, array("-RNFR $remoteFile", "-RNTO $remoteFile.downloaded"));
    curl_setopt($curl, CURLOPT_POSTQUOTE, array("-RNFR $remoteFile -RNTO $remoteFile.downloaded"));
    curl_setopt($curl, CURLOPT_POSTQUOTE, array("rename $remoteFile $remoteFile.downloaded"));

我得到的错误看起来像:

ERROR  : QUOT string not accepted: -RNFR $remoteFile -RNTO $remoteFile.downloaded

最佳答案

以防将来有人发现自己在这里。

我的问题是 $remoteFile 解析为类似 /remote_folder/remote_file.txt 的内容,但由于我的 ftp 连接已经包含文件夹,类似 ftp ://www.example.com/remote_folder/remote_file.txt,我不应该在 RNFRRNTO 中指定文件夹。

关于php - 使用 php cURL 在 ftp 站点上移动文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9726796/

相关文章:

php - 从具有未知数量值的数组创建 PHP 嵌套数组

php - 使用 Symfony 2 序列化器对对象中的嵌套结构进行非规范化

php - 使用 CURLOPT_POSTFIELDS 时数组 2 字符串转换

ruby - Errno::EPIPE:使用 Net::FTP 的管道损坏

java - 在另一台服务器上创建文件

php - 如何在邮件函数的消息正文中打印复选框数组

PHP cURL - 线程安全吗?

php - 无法使用带有 curlopt_stderr 和 curlopt_file 的 PHP cURL 写入文件

java - 带有 FTP 登录错误的 HTTPS 客户端 : javax.net.ssl.SSLException: 502 SSLv23/TLSv1 java

php - 单击带有 JavaScript 的链接