Ask Me Help Desk

Ask Me Help Desk (https://www.askmehelpdesk.com/forum.php)
-   Internet & the Web (https://www.askmehelpdesk.com/forumdisplay.php?f=177)
-   -   PHP ftp functions (https://www.askmehelpdesk.com/showthread.php?t=11138)

  • Jul 20, 2005, 04:26 AM
    mickdanger
    PHP ftp functions
    I am trying to write a page to ftp files from my PC to my website. I am able to connect and log in using ftp_connect() and ftp_login(), but the ftp_put function won't work. What do I use as the values for the parameters?

    $upload= ftp_put($conn_id,$destination_file,$source_file,FT P_ASCII);
    if (!$upload)
    {echo"sorry, didn't work.";}
    else
    {echo"OK!";}
    ftp_close($conn_id);



    ?>
  • Jul 20, 2005, 04:56 AM
    LTheobald
    Whenever you get stuck on a PHP problem, check the PHP manual first. It's fantastic for things like this - PHP Manual: ftp_put(). There is also a full example for you to take a look at.

    The parameters needed are in your example are:

    $conn_id
    This is the FTP connection you established using ftp_connect()

    $destination_file
    The file path of what you want to send. E.g. 'C:\test.txt'

    $source_file
    Where you want this file stored on your FTP server. E.g. '\public_html\test.txt'

    FTP_ASCII
    This is a constant defining the transfer mode. It must either be FTP_ASCII (used for text (ASCII) based files) or FTP_BINARY for binary files (executables, sound files etc.) Note: There was a space in the FTP_ASCII constant in your example - remove that or the function won't work.


    For a full list of PHP's FTP functions, check here

    One final tip: When posting PHP code into the forum, surround it by the [ code ][/ code ] brackets (remove spaces). It makes it look better:

    Code:

    <?php
    function sayHello() {
        // Code is formatted nicely
        echo 'Hello world!';
    }
    ?>


  • All times are GMT -7. The time now is 06:34 PM.