I've been trying out this function and while it connects okay, the error seems to occur in the file I'm trying to put on my hard drive...

Using searches and consequently Devsheds tutorial to get me started...

<?php
// connect to FTP server
$conn = ftp_connect("ftp.site.com");
// log in with username and password
ftp_login($conn, "username", "password");
// get remote system type
ftp_systype($conn);
// change directory to "public_html"
ftp_chdir($conn, "www.site.com/public_html");
// download file
ftp_get($conn, "download.php", "index.php", FTP_ASCII);
// close connection
ftp_quit($conn);
?>

(the www.site.com before public html is due to some strange system my host has)

I then get the error...

Warning: error opening download.php in /home/1030/username/www.site.com/public_html/ftp.php on line 11

Any help in how to sort this would be much appreciated.

    Is the error in reading or writing the file?

    Are you trying to transfer the file from one server to another, or are they both on the same server?

    Is the file you are trying to download in the same directory as you are running this script?

      "Is the error in reading or writing the file?"

      I'm not sure, thats the error I got, I tried to upload and download a file with no joy.

      "Are you trying to transfer the file from one server to another, or are they both on the same server?"

      Trying to download/upload between the site and the users HD. (Probably missing some crucial variable somewhere)

      "Is the file you are trying to download in the same directory as you are running this script?"

      Yes, both are in public_html.

      Thanks for any help, the hosters went down an hour ago so I may as well get some sleep 🙂

        I thought that the FTP functions were to connect the php script to an FTP server somewhere else. I didn't think there was a way to connect to the users hard drive. I think you have to deal with forms and file inputs to get uploads to work. And downloads can just be a link.

          I don't think so...
          From Devshed...

          "Now, that covers the various FTP functions that PHP provides - but, just by itself, it isn't enough. The true power of these functions becomes visible only when they're combined into a single application which provides file transfer and file management capabilities. Since we're talking about FTP functions, it seems obvious that the best application for such a demonstration would be a Web-based FTP client - which is exactly what's coming up next!"

          Thats what I'm looking for, a system that will allow simple transfers and deletions from one section of my site via FTP without giving users full access to all the sections.

          I mean everything on there seems to suggest it can be done, it even talks about local host at one point, this must be the HD, right?

          Thanks again

            ftp_get -- Downloads a file from the FTP server.
            Description

            int ftp_get (int ftp_stream, string local_file, string remote_file, int mode)

            Returns true on success, false on error.

            ftp_get() retrieves remote_file from the FTP server, and saves it to local_file locally. The transfer mode specified must be either FTP_ASCII or FTP_BINARY.

            I'm sure this should work, and I checked phpinfo, its all supported, I mean it connects to the FTP server fine!

              local host would be the server that the php script is running on.

                I still see this as server to server... I'll post a question to see if anyone else can clarify.

                  2 months later

                  Hi, I have seen your problem. I have your problem too. How have you resolve the problem???
                  Thanks Marco

                  James wrote:

                  I've been trying out this function and while it connects okay, the error seems to occur in the file I'm trying to put on my hard drive...

                  Using searches and consequently Devsheds tutorial to get me started...

                  <?php
                  // connect to FTP server
                  $conn = ftp_connect("ftp.site.com");
                  // log in with username and password
                  ftp_login($conn, "username", "password");
                  // get remote system type
                  ftp_systype($conn);
                  // change directory to "public_html"
                  ftp_chdir($conn, "www.site.com/public_html");
                  // download file
                  ftp_get($conn, "download.php", "index.php", FTP_ASCII);
                  // close connection
                  ftp_quit($conn);
                  ?>

                  (the www.site.com before public html is due to some strange system my host has)

                  I then get the error...

                  Warning: error opening download.php in /home/1030/username/www.site.com/public_html/ftp.php on line 11

                  Any help in how to sort this would be much appreciated.

                    a month later

                    Yes I'm also trying to download a file using ftp_fet() but it showed me

                    Warning: error opening 1.doc in /home/bdinfo/bangladeshinfo.com/docs/press/ftp_fget.php3 on line 16
                    FTP get failed

                    so what can i do now . Could u please help how to solve this problem.

                    <?php
                    do {
                    $conn_id = ftp_connect("ftp server");
                    if (!conn_id) {
                    echo("Connection failed<br>");
                    break;
                    }
                    $login_result = ftp_login($conn_id, "username", "password");
                    if (!$login_result) {
                    echo("Login failed<br>");
                    break;
                    }
                    $b = ftp_get($conn_id, "1.doc", "1.doc", FTP_BINARY);
                    if (!$b) {
                    echo("FTP get failed<br>");
                    break;
                    }
                    echo("OK<br>");
                    } while (0);
                    if ($conn_id) {
                    ftp_quit($conn_id);
                    }

                    ?>

                    please help me

                    sayma

                      18 days later

                      Hi folks,

                      I had the same problem and this is the solution:

                      Problem lies in the previous page (propably html form):

                      <FORM enctype="multipart/form-data" action="upload2.php" method="POST">
                      <input type=file name=upfile size=19>
                      </FORM>

                      You must specify the enctype and method. It doesn't default POST for files.

                      upload2.php:

                      $conn = ftp_connect(...
                      .
                      .
                      .
                      ftp_put($conn, "$upfile_name", "$upfile", FTP_BINARY);

                      Important. upfile is the value passed by the previous control. It is a temporary php file (/temp/phpSQAA). The actual file name is passed through upfile_name, which has the basename filename (no directories. This can be substituted to whatever you would like.

                      Hope this helps,

                      Nikos Balkanas

                        Write a Reply...