Copy files across servers

Hello. I’m trying to write a php script that just copies files from one server to another. Is there an easy way to do that without using ssh2 or ftp_connect()? I don’t have permission to install the ssh2 library and ftp_connect() won’t work on our servers.

Can anybody give me any leads here?

Thanks.

not sure what your options are other than manually downloading to you local box and then upload to the other.

You can try something like this:
[php]<?php

set_time_limit(600); // set 10 minutes timeout

// read source file via http
$fs = fopen(“http://www.website.com/file.zip","rb”);
if($fs){
// write destination file into a local directory
$fd = fopen(“uploads/file.zip”, “wb”);
while (!feof ($fs)) {
$buff = fread($fs, 4096);
fwrite($fd, $buff);
}

fclose($fs);
fclose($fd);

}
?>
[/php]

Note, you’ll need allow_url_fopen set On in your php.ini and the destination directory on local server must be writable by php process.

Sponsor our Newsletter | Privacy Policy | Terms of Service