Jump to content

[function.mkdir]: No such file or directory


gomango

Recommended Posts

I was looking for a script that could be set as a cron job to transfer files form one site to another as they are changed.  I googled, and then I hit hotscripts.com.  Found a little script that I think would work if I could figure out the errors.

 

I have googled, and I researched the function "mkdir" but Im not sure what is going on here. 

 

I uploaded a few files using ftp in a folder called "test" The files were called test1.txt,test2.txt... ect.

 

Log in works because the script finds all the files, and attempts to upload them.  The problem is that the folder is never created, and thus no place to upload to.

 

Could anyone tell me what Im missing here?  I verified the directories with a local ftp connection. Here is the script as it looks from hotscripts.com

 

<?
/***************
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 shinda@gmail.com. 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/";

********************************


/*****************************************
           User Options
******************************************/		   
$ftp_server = "ftp.mysite.com";
$ftp_user_name = "myusername";
$ftp_user_pass = "mypassword";
$ftp_dir = "/htdocs/newweb/test"; 

$dirLocal = "/public_html/"; //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>";
			}

		}
	}
}
}
?> 

 

I uploaded the file and ran it, and it gives the following error...

 

Starting 1190559323

/htdocs/newweb/test/test1.txt

 

Warning: mkdir() [function.mkdir]: No such file or directory in /home/diybandm/public_html/ftp.php on line 91

 

Warning: Invalid argument supplied for foreach() in /home/diybandm/public_html/ftp.php on line 85

/htdocs/newweb/test/test2.txt

 

Warning: mkdir() [function.mkdir]: No such file or directory in /home/diybandm/public_html/ftp.php on line 91

 

Warning: Invalid argument supplied for foreach() in /home/diybandm/public_html/ftp.php on line 85

/htdocs/newweb/test/test3.txt

 

Warning: mkdir() [function.mkdir]: No such file or directory in /home/diybandm/public_html/ftp.php on line 91

 

Warning: Invalid argument supplied for foreach() in /home/diybandm/public_html/ftp.php on line 85

/htdocs/newweb/test/test4.txt

 

Warning: mkdir() [function.mkdir]: No such file or directory in /home/diybandm/public_html/ftp.php on line 91

 

Warning: Invalid argument supplied for foreach() in /home/diybandm/public_html/ftp.php on line 85

 

The server that is running the script is using PHP Version 5.2.3 on linux. 

 

Any ideas of what the problem is?

Thanks

Dave

 

 

Link to comment
Share on other sites

I added an echo to see what the script was using for $file2, and $file3.  The optput was a bit unexpected...

 

/htdocs/newweb/test///htdocs/newweb/test/test1.txt

/public_html//htdocs/newweb/test/test1.txt

 

So I ask now... am I chasing the wrong part of the script?  Shouild I be looking at the foreach part of the script?

 

foreach($contents as $file){

$file2 = "$dirRemote/$file";

$file3 = "$dirLocal/$file";

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.