Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

make directory problem - ftp

Status
Not open for further replies.

MJB3K

Programmer
Jul 16, 2004
524
GB
Hi, i have this code to make a directory on my server, but it is not working?? any ideas??

Code:
function FtpMkdir($path, $newDir) { 
   
       $server='host'; // ftp server 
       $connection = ftp_connect($server); // connection 
   
  
       // login to ftp server 
       $user = "username"; 
       $pass = "pass"; 
       $result = ftp_login($connection, $user, $pass); 

   // check if connection was made 
     if ((!$connection) || (!$result)) { 
       return false; 
       exit(); 
       } else { 
         ftp_chdir($connection, $path); // go to destination dir 
       if(ftp_mkdir($connection,$newDir)) { // create directory 
           return $newDir; 
       } else { 
           return false;        
       } 
   ftp_close($conn_id); // close connection 
   } 

} 
FtpMkdir("work", $u);

the directory i would like to make the folder in is called work!

[MAIN DIR] > [SCHOOL] > [WORK] > [MAKE FOLDER HERE]

these are the errors i get:

Code:
Warning: ftp_chdir(): Can't change directory to work: No such file or directory in /home2/webrevol/public_html/school/signup3.php on line 32

Warning: ftp_mkdir(): Can't create directory: File exists in /home2/webrevol/public_html/school/signup3.php on line 33
any ideas??


Regards,

Martin

Gaming Help And Info:
 
The first one sounds straightforward to me. The "work" directory does not exist on that FTP server.

Have you FTPed into the server by hand to verify that the "work" directory exists and that you have permission to change to that directory?


Want the best answers? Ask the best questions!

TANSTAAFL!!
 
yes, the "work" directory does exist under the school directory in this format:

[MAIN DIR] > [SCHOOL DIR] > [WORK DIR]

what sort of permissions would i need??

what CHMOD would it need to be?


Regards,

Martin

Gaming Help And Info:
 
At the risk of sounding pedantic...

Have you, from the server which will be running this script, used FTP and the credentials you use in your script to connect to the "host" server? Can you change to the "work" directory? Can you create the subdirectory, all from within the FTP client?


As to permissions, I can't say. What OS is the FTP server running?


Want the best answers? Ask the best questions!

TANSTAAFL!!
 
It's running Linux.

Yes i can connect to the server, make directories from the FTP client. I am using SmartFTP.

what is the ftp_close($conn_id); ?? what is $conn_id??



Regards,

Martin

Gaming Help And Info:
 
it gives these errors:
Code:
Warning: ftp_chdir(): Can't change directory to school/work: No such file or directory in /home2/webrevol/public_html/school/createdir.php on line 17

Warning: ftp_mkdir(): Can't create directory: File exists in /home2/webrevol/public_html/school/createdir.php on line 19
but it creates the folder in the root directory below the public_html folder?

any more ideas??


Regards,

Martin

Gaming Help And Info:
 
The problem is, for reasons difficult to surmise with the information given, that when you FTP into the server from the script, the script cannot change to the "work" directory. There are lots of reasons why this could be true.


Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Why can't it change directory?? What reasons would they
be??

The script is in the school directory above the work dir.

[SCHOOL][SCRIPT HERE] > [WORK]



Regards,

Martin

Gaming Help And Info:
 
yea it is on the same machine, i tried using the mkdir(); command, but when you do, you cant upload any files to it via ftp. What do you have to do to make it so you can upload via ftp on the same dir that you just made?

any ideas??

Regards,

Martin

Gaming Help And Info:
 
I strongly recommend against using HTTP or FTP from within the same system. It's an unnecessary load on the server and it slows things down.

Keep in mind one thing. When you create a directory from a PHP web script, the owner of the directory will be the user as which your web server runs. If the user you're logging in as by FTP doesn't have permissions to the file, use chown() and/or chmod() to give the the FTP user ownership or permission to the file.

Do you have console access to this server? If so, going to the script directory and performing an "ls -l" will tell you a lot about what's going on.


Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top