copying one file from one server to another

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jasongr
Forum Contributor
Posts: 206
Joined: Tue Jul 27, 2004 6:19 am

copying one file from one server to another

Post by jasongr »

Hello

I have 2 servers
server 1 at (fake IP) 1.2.3.4
server 2 (server I am locally running on)
I have a file called test.zip in server 1. The file is located at the server's htdocs folder
for example: http://1.2.3.4/test.zip

I am now in server 2 and I want to "pull" (copy) that file from server 1

I created a php file called copy.php in server2 and tried the following:

Code: Select all

ini_set('max_execution_time', 1800);
set_time_limit(0);

$source = "http://1.2.3.4/test.zip";
$target = "/usr/local/apache/htdocs/test.zip";

if (!copy($source, $target)) {
	print "Failed to copy";
}
else {
	print "Success";
}
When I run this simple script, I get the following error:

Code: Select all

Warning: copy('/usr/local/apache/htdocs/test.zip') [function.copy]: failed to open stream: Permission denied in /usr/local/apache/htdocs/copy.php on line 9
Failed to copy
what could be causing this?
maybe I can use curl_exec to get the file instead of using copy
Note, that the file is very large 70MB. could this be a problem for copy? or even for the script which might time out?

regards
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post by n00b Saibot »

if its accesible thru http/ftp/any tp.. then you can use copy() but not otherwise... also you can write a transfer script which will copy the file to bytestream which you can read on local side :wink:
jasongr
Forum Contributor
Posts: 206
Joined: Tue Jul 27, 2004 6:19 am

Post by jasongr »

I managed to get a workaround by using curl in Linux to copy the file
Post Reply