Hi everybody

I'm using FTP to move files from one site to another. That is working out just fine.

I just have one question. I'm using ftp_chdir() to move to a directory. If this directory doesn't exists I want to create it using ftp_mkdir().

Are there any simple way of checking if this directory excists, before I either move to it or creates it?

😃 Tore

    You may be able to use [man]file_exists/man to check for that.

    If not, then another way would be to regard a failed ftp_chdir() as indicating no such directory, and so use ftp_mkdir() after that.

      Hi Laserlight

      Thanks for the tips. I tried to use something like this:

      if(!ftp_chdir($conn_id, $cp_dir))
      {
      ftp_mkdir($conn_id, $cp_dir);
      ftp_chdir($conn_id, $cp_dir);
      }

      but if the if-statement fails it is giving a quite annoying Warning message on the screen.

      I will check out how to do it with file_exists()

      Tore

        but if the if-statement fails it is giving a quite annoying Warning message on the screen.

        Then suppress that with the @ operator.
        if(!@ftp_chdir($conn_id, $cp_dir))

          Thanks a lot Laserlight

          That solved my problem 😃

          I'm learning something new in here every day. Where can I read more about the @-operator?

          In addition to this I also want to chmod my new directory. I already tried ftp_chmod() but it seams like my web-server doesn't take this. What can I do instead?

          Tore

            Where can I read more about the @-operator?

            From the PHP Manual's section on Error Control Operators.

            I already tried ftp_chmod() but it seams like my web-server doesn't take this. What can I do instead?

            You could try using [man]chmod/man, but that probably wont work either.
            Contact your web host and ask about it.

              I also tried chmod() but that is giving me strange error messages.

              Thanks for the help; my main problem is solved.🆒

                Write a Reply...