简体   繁体   English

使用cURL将文件从URL上传到FTP

[英]Upload file from URL to FTP using cURL

I need to upload a file to my FTP server using cURL. 我需要使用cURL将文件上传到我的FTP服务器。 let me explain better. 让我解释得更好。

I have this URL http://www.server.com/file.zip and I need to copy the "file.zip" to a FTP server without having to download it to my PC. 我有此URL http://www.server.com/file.zip ,我需要将“ file.zip”复制到FTP服务器,而不必将其下载到PC。

I have seen some examples that use cURL to upload files but are they are my hard drive and I need is upload from a URL. 我看过一些使用cURL上传文件的示例,但是它们是我的硬盘驱动器,我需要从URL上传。

Thank you for your help. 谢谢您的帮助。

Since you don't know if you're saving it properly, just use the stream. 由于您不知道保存的是否正确,请使用流。

<?php

// open some file for reading
$file = 'http://server.com/file.zip';
$fp = fopen($file, 'r');

// set up basic connection
$conn_id = ftp_connect($ftp_server);

// login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);

// try to upload $file
if (ftp_fput($conn_id, $file, $fp, FTP_ASCII)) {
    echo "Successfully uploaded $file\n";
} else {
    echo "There was a problem while uploading $file\n";
}

// close the connection and the file handler
ftp_close($conn_id);
fclose($fp);

?>

By the way, I'm just using PHP Manual examples for these answers. 顺便说一下,我只是使用PHP手册示例来获得这些答案。 You should, too. 你也应该 Look here . 这里

i know its abit late but for anyone who needs this i spent hours looking for something similar 我知道它的迟到了,但是对于任何需要它的人,我花了几个小时寻找类似的东西
http://bgallz.org/1345/php-upload-multiple-files-url/ http://bgallz.org/1345/php-upload-multiple-files-url/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM