Jump to content

PHP FTP Copying files from server to server.


sean04

Recommended Posts

What I'm trying to do is copy all  files from one server to another folder on another server. Here is what I have have so far..

 

<?PHP

//connection settings
$ftp_server = "server";
$ftp_user_name = "user";
$ftp_user_pass = "pass";

$dir = "/var/test/";
$destination_file = "/test/";

// set up basic connection
$conn_id = ftp_connect($ftp_server);

// login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);

// check connection
if ((!$conn_id) || (!$login_result))
{
	echo "FTP connection has failed!";
	echo "Attempted to connect to $ftp_server for user $ftp_user_name";
	exit;
}
else
{
	echo "Connected to $ftp_server, for user $ftp_user_name";
}


if (ftp_chdir($conn_id, $dir)) {
    	echo " <br/>Current directory is now: " . ftp_pwd($conn_id) . "\n<p/>";
} else {
	echo "Couldn't change directory\n<p/>";
}

$buff = ftp_rawlist($conn_id, $dir);

foreach($buff as $files)
{
	echo $files. "<br/>";

	if (ftp_get($conn_id, $destination_file."test.file", $dir."test.txt", FTP_BINARY)) {
    		echo "<br/>Successfully written to $destination_file\n";
	} else {
    		echo "There was a problem\n";
}

?>

 

That doesn't work. Any ideas?

 

Thanks,

Sean

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.