FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Copy files between server.





Philip
is there a way to copy file between server using php ?
but still make it a live*copy still running* when we close our browser ?

since i need to download some manga, but it seem the manga server running slow, and i want download the manga from my server. of course i no need to wait until my server copy manga finished.

thanks,
coreymanshack
im not understanding....do you want to get the image with the php or what?
Philip
i want to copy file using php. and between server,
let see, if there is www.google.com/manga.zip and i want to copy this file to my site www.mysite.com/manga.zip.

but i don't want to wait until finished the copy to close my browser.
and is there someone now, what criteria to make a file can downloadable with resume and multiple download ?

thanks,
hexkid
Philip wrote:
i want to copy file using php. and between server,
let see, if there is www.google.com/manga.zip and i want to copy this file to my site www.mysite.com/manga.zip.

but i don't want to wait until finished the copy to close my browser.
and is there someone now, what criteria to make a file can downloadable with resume and multiple download ?


Use CURL in a cronjob to copy the file(s), getting the info from a database (or a text file -- pay attention to file locking) written by a web page.

... or you can try to do that directly from the web page with Process Control Functions ... can't help you there.
Philip
er..... sorry, but how can i use this CURL function ??


thanks ^_^"
Antoine_935
try this: http://sf.net/projects/phtp

it was last updated long ago, but it works great. and I'm currently working on a 3.0 version
hexkid
Philip wrote:
er..... sorry, but how can i use this CURL function ??


I changed an example from the manual a little bit to deal with files ...
This code needs error-checking!
Code:
<?php
################
## NOT TESTED ##
################

// create a new CURL resource
$ch = curl_init();

// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, "http://www.google.com/manga.zip");
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

set_time_limit(300); # 5 minutes for PHP
curl_setopt($ch, CURLOPT_TIMEOUT, 300); # and also for CURL

$outfile = fopen('/mysite.com/manga.zip', 'wb');
curl_setopt($ch, CURLOPT_FILE, $outfile);

// grab file from URL
curl_exec($ch);
fclose($outfile);

// close CURL resource, and free up system resources
curl_close($ch);

### As this is meant to be run from cron,
### it doesn't need to output anything.
### It might be a good idea to mail yourself
### at the end though (or in case of errors)
mail('yourself@example.com', 'cron job with CURL completed', '(empty body)');
?>
Philip
curl_setopt($ch, CURLOPT_BINARYTRANSFER, true); <-- what is this for ?

anyway, it is work ^_^

thanks,
coreymanshack
thanks for clearing that up phillip... i now see that someone else has already gotten around to helping you with your problem.. good luck with that stuff!
Philip
coreymanshack wrote:
thanks for clearing that up phillip... i now see that someone else has already gotten around to helping you with your problem.. good luck with that stuff!


uhm, you see, i have ended up my day with php, but it seem still amateur about it hehe ^_^"
hexkid
Philip wrote:
curl_setopt($ch, CURLOPT_BINARYTRANSFER, true); <-- what is this for ?


from the manual page for curl_setopt()
Quote:
TRUE to return the raw output when CURLOPT_RETURNTRANSFER is used.

I used CURLOPT_RETURNTRANSFER to stop the file from being sent to the browser; I'm not really sure CURLOPT_BINARYTRANSFER is needed, but I guess it won't break the script if it isn't Smile

Anyway, I put that in because the file download should not have bytes interpreted ("\r\n" converted to "\n", "\0" stripped at end of file, ...). You are free to try it without that option and verify if it works.
Philip
i made a function like this,
but it seem my browser still need to wait until the copy finished. -_-"

Code:
function download_pretending($url,$user_agent) {
   $ch = curl_init();
   curl_setopt($ch, CURLOPT_URL, $url);
   curl_setopt ($ch, CURLOPT_HEADER, 0);   
   curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
   curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
   set_time_limit(3000); # 5 minutes for PHP
   curl_setopt($ch, CURLOPT_TIMEOUT, 3000); # and also for CURL   
   $result =base64_encode(curl_exec ($ch));
   curl_close ($ch);
   if(!$handle = fopen(basename($url).".htm", 'w+'))
   {
       echo "Cannot open file ".basename($url).".htm";
         exit;
   }
    if (fwrite($handle, $result) === FALSE) {
        echo "Cannot write to file ".basename($url).".htm";
        exit;
    }
   echo basename($url).".htm";
   fclose($handle);
}


ock1991
.. thats why its supposed to be run through a cron job. cron jobs are executed by the computer which your site is on and thus do not need your browser' presence, and can download without you executing the script.
Philip
then, how can i set this to cron job ?
thanks,
remshad
how i modify this script for using password and user name(cookies) to copy a file from password protected remote server to our serve



any help appreciated
Thanks
rvec
you could take a look at this script (link posted in the first post):
http://www.frihost.com/forums/vt-109791.html

It uses curl to login to and logout from frihost with cookies.
Related topics
FTP program
Ragnarok Online private server...
Dual Moniters
Free Mac FTP Software
To share files on a Windows XP and a Mac OS X
Lineage II (C4 chronicle)
Moving File Between Server!
how can u share files between two wifi enabled laptops?
Need Help, how to transfer to files to server using $_GET
CuteFTP Professional
How to Transfer Hosting Account..
Moving files between Debian and Windows. Locale issues?
CORE FTP LE help
Can't upload files on server
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.