PHP - ftp_put() not uploading

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • empiresolutions
    New Member
    • Apr 2006
    • 162

    PHP - ftp_put() not uploading

    ftp_put() is not working. this is what i have.

    [PHP]
    $host = "www.site.c om";
    $ftp_user_name = "username";
    $ftp_user_pass = "password";

    // declair files
    $remote_file = "ITS_BLI_0".$_P OST['id'].".csv"; // root level
    $file = "/upload/ITS_BLI_0".$_PO ST['id'].".csv"; // this file dir is root/manager/posts/

    // connect to remote server
    $hostip = gethostbyname($ host);
    $conn_id = ftp_connect($ho stip);

    // login with username and password
    $login_result = ftp_login($conn _id, $ftp_user_name, $ftp_user_pass) ;

    // IMPORTANT!!! turn passive mode on
    ftp_pasv ( $conn_id, true );

    if ((!$conn_id) || (!$login_result )) {

    echo "FTP connection has failed!";
    echo "Attempted to connect to $host for user $ftp_user_name" ;
    die;

    } else {

    // upload a file
    if (ftp_put($conn_ id, $remote_file, $file, FTP_ASCII)) {

    echo "successful ly uploaded $file<br>";

    } else {
    /** IM GETTING THIS ERROR **/
    echo "There was a problem while uploading $file to $host<br>";

    }

    // close the connection
    ftp_close($conn _id);

    }

    [/PHP]
    • I have done the following allready.
    • Used both FTP_ASCII and FTP_BINARY in ftp_put().
    • Passive mode must be on.
    • I have tried ftp_fput().


    Is there a fix? Or maybe a way to view why its erroring on ftp_put().

    thanks, [es]
  • Banfa
    Recognized Expert Expert
    • Feb 2006
    • 9067

    #2
    You haven't said which of your output messages you are getting when you attempt, however I question this piece of code

    [php]
    $file = "/upload/ITS_BLI_0".$_PO ST['id'].".csv"; // this file dir is root/manager/posts/
    [/php]

    is the upload directory really at the root of your directory structure?

    Even if it appears atthe root of your hosted website that is not the root of that machines dirctory structure and php works off the machine root not the site root.

    So I would say check that the soruce file is where you think it is, easily done with the file_exists function

    [php]
    if (file_exists($f ile))
    {
    echo "The file $filename exists";
    }
    else
    {
    echo "The file $filename does not exist";
    }[/php]

    Comment

    • empiresolutions
      New Member
      • Apr 2006
      • 162

      #3
      thats helped alot thanks. i fixed it. simple pathing error.

      old -

      $file = "/upload/ITS_BLI_0".$_PO ST['id'].".csv";

      new -

      $file = "../../upload/ITS_BLI_0".$_PO ST['id'].".csv";

      Comment

      • r4ccoon
        New Member
        • Jul 2007
        • 3

        #4
        try my post here...

        http://www.thescripts. com/forum/showthread.php? p=2710795#post2 710795

        Comment

        Working...