SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    He's No Good To Me Dead silver trophybronze trophy stymiee's Avatar
    Join Date
    Feb 2003
    Location
    Slave I
    Posts
    23,424
    Mentioned
    2 Post(s)
    Tagged
    1 Thread(s)

    FTP through PHP failing without a "real" error

    I have basic FTP upload occurring in a script that does work properly. I tested in by connecting and uploading to a site on the same server and it works flawlessly. However, when I try to connect to a site on a different server it always fails but without a "real" error. By real I mean it isn't a fatal error or an error message is not returned by the remote server. Instead I get this:

    Warning: ftp_put() [function.ftp-put]: PORT command successful in /path/to/file.php on line 112

    To me this looks like it is connecting and communicating successfully but not completing the upload. Might this be a problem with the script timing out before it completes? The file being uploaded is only 10k in size so I would be surprised if it took very long to complete the actual file upload.

    Additionally, sometimes I do get a zero byte file to be "uploaded" but that is about as far as it gets. I've tried it with a couple of servers and get the same error. I have tried it with and without going into passive mode.

    I did a Google search for this and got nothing useful so I'm hoping someone has had a similar experience and can enlighten me as to the problem.

  2. #2
    SitePoint Wizard cmuench's Avatar
    Join Date
    Jul 2005
    Location
    At my computer
    Posts
    2,251
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    sounds like something in your php script could be weird. Here is a pretty good ftp uploader script.
    PHP Code:
    I fixed the below upload script to work with Windows uploads (and updated some of the syntax). I also added a Javascript "progress indicator" for those of us who don't use PHP 5.2

    <?php
    if(isset($_POST['start_upload']) && $_FILES['txt_file']['name'] != ""){
        
        
    $local_file $_FILES['txt_file']['tmp_name']; // Defines Name of Local File to be Uploaded

        
    $destination_file "/".basename($_FILES['txt_file']['name']);  // Path for File Upload (relative to your login dir)

        // Global Connection Settings
        
    $ftp_server "127.0.0.1";      // FTP Server Address (exlucde ftp://)
        
    $ftp_user_name "username";     // FTP Server Username
        
    $ftp_user_pass "password";      // Password

        // Connect to FTP Server
        
    $conn_id ftp_connect($ftp_server);
        
    // Login to FTP Server
        
    $login_result ftp_login($conn_id$ftp_user_name$ftp_user_pass);
       
        
    // Verify Log In Status
        
    if ((!$conn_id) || (!$login_result)) {
            echo 
    "FTP connection has failed! <br />";
            echo 
    "Attempted to connect to $ftp_server for user $ftp_user_name";
            exit;
        } else {
            echo 
    "Connected to $ftp_server, for user $ftp_user_name <br />";
        }

        
    $upload ftp_put($conn_id$destination_file$local_fileFTP_BINARY);  // Upload the File
       
        // Verify Upload Status
        
    if (!$upload) {
            echo 
    "<h2>FTP upload of ".$_FILES['txt_file']['name']." has failed!</h2><br /><br />";
        } else {
            echo 
    "Success!<br />" $_FILES['txt_file']['name'] . " has been uploaded to " $ftp_server $destination_file "!<br /><br />";
        }

        
    ftp_close($conn_id); // Close the FTP Connection
    }
    ?>

    <html>
        <head>
            <script type="text/javascript">
                window.onload = function() {
                    document.getElementById("progress").style.visibility = "hidden";
                    document.getElementById("prog_text").style.visibility = "hidden";
                }
               
                function dispProgress() {
                    document.getElementById("progress").style.visibility = "visible";
                    document.getElementById("prog_text").style.visibility = "visible";
                }
               
            </script>
           
        </head>
        <body>
            <form action="<?php echo $_SERVER['PHP_SELF'];?>" method="POST" enctype="multipart/form-data">
                Please choose a file: <input name="txt_file" type="file" size="35" />
                <input type="submit" name="start_upload" value="Upload File" onClick="dispProgress()" />
            </form>
           
            <!-- Link to progress file: see http://www.ajaxload.info/ for animated gifs -->
            <img id="progress" src="http://www.your.site/images/progress.gif" />
            <p id="prog_text" style="display:inline;"> Upload Started!</p>
           
        </body>
    </html>

  3. #3
    He's No Good To Me Dead silver trophybronze trophy stymiee's Avatar
    Join Date
    Feb 2003
    Location
    Slave I
    Posts
    23,424
    Mentioned
    2 Post(s)
    Tagged
    1 Thread(s)
    That's pretty much what I have in my script and is similar to other code I've seen online. That makes me believe it is more of a server issue then a code issue. Although I would love for it to be a code issue. That's easier to fix.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •