Reputation: 141
I'm looking for a script you can auto download file from one server and upload to a database using php and cron jobs. Can anyone point me in the right direction please?
Thanks.
Upvotes: 0
Views: 3388
Reputation: 95131
you can use ftp
and php that functionality : http://www.php.net/manual/en/book.ftp.php
Prove of Concept
$remoteUrl = "http://balabla/abc.pdf" ; // to remote file
$localTemp = "temp" ; // Temp directory
$file = 'somefile.txt';
$ftpServer = "";
$ftpUsername = "";
$ftpPassword = "" ;
$serverPath = 'data/upload/'; // this most exist on your the server you are uploading to
//Get Remote FIle
$localFile = $localTemp . DIRECTORY_SEPARATOR . basename($remoteUrl);
file_put_contents($fileName, file_get_contents($remoteUrl));
//Upload The File
$connID = ftp_connect($ftpServer);
$loginID = ftp_login($connID, $ftpUsername, $ftpPassword);
if(!$connID || !$loginID)
{
die("Can't Connect to FTP");
}
ftp_chdir($connID, $serverPath); //Change Directory
if (ftp_put($connID, $localFile, basename($localFile), FTP_BINARY )) {
echo "successfully uploaded $localFile\n";
} else {
echo "There was a problem while uploading $localFile\n";
}
// close the connection
ftp_close($connID);
I hope it helps
Upvotes: 2