Web Hosting Forums

Results 1 to 6 of 6

This is a discussion on Php Ftp in the Hosting Talk & Chit-chat forum
Anyone ever been able to use ftp with php4? Everything looks ok in my code, but I always get an error. The connection works fine, ...

  1. #1
    Loyal Client
    Join Date
    Nov 2003
    Location
    NC, USA
    Posts
    35

    Php Ftp

    Anyone ever been able to use ftp with php4? Everything looks ok in my code, but I always get an error. The connection works fine, and I see "Connected to...for user..."message. After that I get the "FTP upload has failed" message. Not sure why. I can ftp using the same user/password if I use the windows ftp under the command prompt.
    Here's what I have:


    // check connection
    if ((!$conn_id) || (!$login_result)) {
    echo "FTP connection has failed!";
    echo "Attempted to connect to $ftp_server for user $ftp_user_name";
    exit;
    } else {
    echo "Connected to $ftp_server, for user $ftp_user_name";
    }
    ftp_pasv ( $conn_id, true );
    // upload the file

    $destination_file=$eventIDNum.'.jpg';

    $source_file = "c:\mystuff\web\yac_banner_3.jpg";
    echo ftp_pwd($conn_id);
    $upload = ftp_put($conn_id, $destination_file, $source_file, FTP_BINARY);

    // check upload status
    if (!$upload) {
    echo "FTP upload has failed!";
    } else {
    echo "Uploaded $source_file to $ftp_server as $destination_file";
    }

    // close the FTP stream
    ftp_close($conn_id);

  2. #2
    Ron
    Ron is offline
    Loyal Client
    Join Date
    Aug 2002
    Posts
    7,503
    Check the satus coming back from ftp_pasv() ?

  3. #3
    Community Leader jason's Avatar
    Join Date
    Sep 2001
    Location
    Rochester, NY
    Posts
    5,884
    Given that you are using a DOS path for your source file, I have a feeling that you aren't using the FTP commands correctly. It looks as though you are trying to upload a file from your local machine to the server, and that isn't what the ftp functions are designed to do. The PHP FTP functions are designed to let you connect from your server to another server to transfer files. This is useful when, say you need to automatically connect to a supplier's website to download their new pricing info so that you can import it into yopur shopping cart automatically.

    If you want to allow people to upload files from their computers to your server, then you should use PHP's file upload features. (If you do this, make sure you take precautions to make sure that no one uploads something they shouldn't--it is rather trivial for someone to upload a PHP script and use that to take over your entire site or do any number of other malicious things.)

    Remember, PHP code only runs on the server. When you request a PHP script through your browser, the server finds that files and executes it. The script runs and generates some sort of output (generally HTML) and sends that to the browser. The PHP code never goes to your computer--it is only run on the server. PHP can't access files on your computer and doesn't know (or care) if you are using a PC, a Mac, a PDA--or a smart toaster for that matter.

    I hope I'm interpreting your code correctly and I hope this answer helps you out.

    --Jason
    Jason Pitoniak
    Interbrite Communications
    www.interbrite.com www.kodiakskorner.com

  4. #4
    Ron
    Ron is offline
    Loyal Client
    Join Date
    Aug 2002
    Posts
    7,503
    Interesting! I assumed he was running the php on his PC since he said he tried the same thing using windows FTP. I didn't think that he might be running the php on the remote server...

  5. #5
    Community Leader jason's Avatar
    Join Date
    Sep 2001
    Location
    Rochester, NY
    Posts
    5,884
    Quote Originally Posted by Ron
    Interesting! I assumed he was running the php on his PC since he said he tried the same thing using windows FTP. I didn't think that he might be running the php on the remote server...
    I wasn't sure how to interpret that either, so I just took a guess.

    --Jason
    Jason Pitoniak
    Interbrite Communications
    www.interbrite.com www.kodiakskorner.com

  6. #6
    Loyal Client
    Join Date
    Nov 2003
    Location
    NC, USA
    Posts
    35
    No you're right..it's on the server...not sure what I was thinking. Thanks for the info!

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
  •