fanfavorite Posted July 17, 2007 Share Posted July 17, 2007 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; } Quote Link to comment Share on other sites More sharing options...
akitchin Posted July 17, 2007 Share Posted July 17, 2007 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. Quote Link to comment Share on other sites More sharing options...
fanfavorite Posted July 17, 2007 Author Share Posted July 17, 2007 That makes sense, thanks a lot. I hate when I make mistakes like that lol. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.