La réponse est non, car tu dois passer par du PHP qui va faire office de passerelle entre les deux et donc stocker le fichier en mémoire pour le transférer ensuite en FTP.Je ne peux pas télécharger des fichiers à partir de leurs url en ligne directement dans mon FTP sans passer par le local?
Code : Tout sélectionner
<?php
function download_remote($url , $save_path)
{
$f = fopen( $save_path , 'w+');
$handle = fopen($url , "rb");
while (!feof($handle))
{
$contents = fread($handle, 8192);
fwrite($f , $contents);
}
fclose($handle);
fclose($f);
}
?>Code : Tout sélectionner
<?php
$login_url = 'http://www.somesite.com/login.php';
//These are the post data username and password
$post_data = 'username=someusername&password=somepassword';
//Create a curl object
$ch = curl_init();
//Set the useragent
$agent = $_SERVER["HTTP_USER_AGENT"];
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
//Set the URL
curl_setopt($ch, CURLOPT_URL, $login_url );
//This is a POST query
curl_setopt($ch, CURLOPT_POST, 1 );
//Set the post data
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
//We want the content after the query
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
//Follow Location redirects
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
/*
Set the cookie storing files
Cookie files are necessary since we are logging and session data needs to be saved
*/
curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookie.txt');
//Execute the action to login
$postResult = curl_exec($ch);
?>
Code : Tout sélectionner
<?php
//$url the URL of the supplier
$login_url = 'http://www.suppliersexample.com/';
//These are the post data username and password
$post_data = 'username=blabla&password=blabla';
//Create a curl object
$ch = curl_init();
//Set the useragent
//$agent = $_SERVER["HTTP_USER_AGENT"];
$agent = "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.157 Safari/537.36";
//I'm not sure about it if we should write the agent user that way or not
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
//Set the URL
curl_setopt($ch, CURLOPT_URL, $login_url );
//This is a POST query
curl_setopt($ch, CURLOPT_POST, 1 );
//Set the post data
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
//We want the content after the query
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
//Follow Location redirects
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
/*
Set the cookie storing files
Cookie files are necessary since we are logging and session data needs to be saved
*/
curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookie.txt');
//Execute the action to login
$postResult = curl_exec($ch);
//Var_dump ($postresult);
?>
En regardant dans les logs ou en activant l'affichage des messages d'erreur : post433101.html#p433101j'ai lancé ce script et ça me retourne une page blanche( je travaille dans un environnement local ) comment je peux connaitre l'erreur ?