Jump to content

[SOLVED] ftp_mkdir() expects parameter 1 to be resource


fanfavorite

Recommended Posts

I am trying to ftp an entire folder and all it's contents.  Now the problem with this script is the fact that it won't create directories or copy the files to the remote server.  Now I know the connection is established and the $conn_id is ftp.clientsdomain.com, but I get the errors:

 

ftp_mkdir() expects parameter 1 to be resource, null given in ...

ftp_put() expects parameter 1 to be resource, null given in ...

 

Any ideas on why I am getting this error?  Thanks!

 

-JC

 

$connUser = $g[username];
$connPass = $g[Password];
$startpos = $g[startDir]."/clients";
$connServer = "ftp.";
$connServer .= $g[Domain];

$conn_id = ftp_connect($connServer);
$login_result = ftp_login($conn_id, $connUser, $connPass);

function copyDir($dirName,$startpos) {
if(file_exists($dirName)) {
	$dir = dir($dirName);
     		while($file = $dir->read()) {
          		           if($file != '.' && $file != '..') {
             			if(is_dir($dirName.'/'.$file)) {
				ftp_mkdir($conn_id, $startpos.'/'.$file);
        			             copyDir($dirName.'/'.$file,$startpos.'/'.$file);
             			} else {
        			             ftp_put($conn_id, $startpos.'/'.$file, $filetoupload, FTP_BINARY);
             			}
           		           }
     		}
	$dir->close();
} else {
	return false;
   	}
return true;
}

Link to comment
Share on other sites

if you want to use the connection resource from within a function, you either have to pass it to the function or you have to globalize it:

 

function copyDir($connection,$dirName,$startpos) {
if(file_exists($dirName)) {
	$dir = dir($dirName);
     		while($file = $dir->read()) {
          		           if($file != '.' && $file != '..') {
             			if(is_dir($dirName.'/'.$file)) {
				ftp_mkdir($connection, $startpos.'/'.$file);
        			             copyDir($dirName.'/'.$file,$startpos.'/'.$file);
             			} else {
        			             ftp_put($connection, $startpos.'/'.$file, $filetoupload, FTP_BINARY);
             			}
           		           }
     		}
	$dir->close();
} else {
	return false;
   	}
return true;
}

 

it's all about scope.

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.