Jump to content

PHP Server Copy


silver9990

Recommended Posts

I'm trying to use PHP Server Copy from http://www.shindasingh.com/blog/?p=262

 

I set everything up but when I try to access the script I get this:

 

Warning: Invalid argument supplied for foreach() in /ftp.php on line 69

 

Line 69:

 

		foreach($contents as $file){

 

Here's the code from the script:

 

<?
/***************
PHP Server Copy V .01

Author: Shinda Singh
website: www.shindasingh.com
Release Date: August 2nd / 2006
Last Build: August 2nd / 2006

Script is for general public use. Blah Blah...if you want to donate or feel that this script has saved you some flow then you can paypal it to [email protected]. If you modify if and call it your own, then more power to you. If you modify it copywrite it and call it your own, please don't sue me. Whatever else happens its all good.

USAGE: 

1) Fill out the FTP connection information

$ftp_server = "ftp.yourftpaddress.com";
$ftp_user_name = "ftp-username";
$ftp_user_pass = "ftp-password";
$ftp_dir = "/your/folder/here/";

2) Enter the url where you want to copy all files from ftp to.

$dirLocal = "/your/local/folder/goes/here/";

*** Make sure that the folder is writeable (CHMOD 777)..

3) Save and upload to your server.

4) Run ftp.php by visiting the url or running the cron job.
********************************


/*****************************************
           User Options
******************************************/		   
$ftp_server = "";
$ftp_user_name = "";
$ftp_user_pass = "";
$ftp_dir = ""; 

$dirLocal = ""; //Directory on Local

/************************************************
          DO NOT EDIT BELOW THIS POINT
*************************************************/
	  
// 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);

$dir = $ftp_dir; //Directory on Remote

$contents = ftp_nlist($conn_id, $dir);

echo "Starting ".time()."<br>";

transferFiles($dir, $dirLocal);

function transferFiles($dirRemote, $dirLocal){
global $conn_id;

if ($conn_id != false){

	// get contents of the current directory
	$contents = ftp_nlist($conn_id, $dirRemote);

	foreach($contents as $file){
		$file2 = "$dirRemote/$file";
		$file3 = "$dirLocal/$file";

		if ( (ftp_size($conn_id, $file2) == -1) && !( ($file  == ".") || ($file == "..") ) ){ //Directory
			echo "<b>$file</b><br>";
			mkdir($file3);	//Make Folder
			transferFiles($file2,$file3);
		}
		elseif (ftp_size($conn_id, $file2) > 0) {
			echo "<i>$file</i>";

			//If File Exists Skip.
			if (file_exists($file3)){
				if (ftp_size($conn_id,$file2) == filesize($file3))
					echo "- skipped <br>";
				else {
					ftp_get($conn_id,$file3,$file2,FTP_BINARY,filesize($file3)/9);
					echo "- completed <br>";
				}
			}
			else {
				ftp_get($conn_id,$file3,$file2,FTP_BINARY);
				echo "<br>";
			}

		}
	}
}
}
?> 

Link to comment
https://forums.phpfreaks.com/topic/77665-php-server-copy/
Share on other sites

Let's see if I can help out!

 

Line 69 includes the foreach which iterates over the contents found in $contents, which is populated by ftp_nlist.  It would seem that the ftp connection was successful, but are you sure you are providing the proper directory name and location on the remote server?  For some reason, $contents is empty which implies the directory you provided is wrong or empty.

 

You might need to use the full path, and not a relative path, this is especially important depending on how your host has their accounts set up.  Example:

 

Certain hosts allow you to use /httpdocs as a location if your account is set up in such a manner that supports it.  But others force you to actually use the full path:

 

 

/var/www/vhosts/domain.com/httpdocs

Link to comment
https://forums.phpfreaks.com/topic/77665-php-server-copy/#findComment-401236
Share on other sites

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.