Copying files from another server


This script will allow you to copy files from other server that you own. You only need to specify the ftp host, ftp user name, ftp password, and the folder where the files to be copied are stored. You need to upload this script in the folder where you want to transfer the files. Be sure that the folder where you want to transfer the files is in chmod 777.

<?
$HOST=”domain.com”; //change domain.com with your ftp host
$UN=”username”; //ftp user name
$PW=”pass”; //ftp password
$DIR=”www/location/”; //location of files you want to copy

$conn = ftp_connect($HOST);
if(!$conn) {
exit(”Could not connect to server: $HOST\n”);
}else{
echo “connected”;
}

//exit;
if(!ftp_login($conn,$UN,$PW)) {

ftp_quit($conn);
exit(”Could not log in\n”);
}

echo “current directory is ” .ftp_pwd($conn);

ftp_chdir($conn,$DIR);

echo “<p>Now the current directory is ” .ftp_pwd($conn);

$files = ftp_nlist($conn,”.”);

for($i=0;$i<count($files);$i++) {
echo “Saving $files[$i] <br>”;

if(!ftp_get($conn,$files[$i],$files[$i],FTP_BINARY)) {
echo “Could not download {$files[$i]}\n”;
}
}

ftp_quit($conn);
?>

You must be logged in to post a comment.