SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Hybrid View

  1. #1
    SitePoint Enthusiast RahulKumar's Avatar
    Join Date
    Jul 2004
    Location
    Germantown
    Posts
    44
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Using ftp_put() with a string...

    Can I use ftp_put to put the variable $bleh into a file?

  2. #2
    SitePoint Zealot Selatos's Avatar
    Join Date
    Aug 2002
    Location
    USA
    Posts
    144
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    wouldn't it be easier to use fopen(), frwite(), etc?

  3. #3
    SitePoint Wizard silver trophy someonewhois's Avatar
    Join Date
    Jan 2002
    Location
    Canada
    Posts
    6,364
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah, use fopen.

    PHP Code:
    <?php
    $bleh 
    'ALSDJFLAKJFSDAFSD';
    $fp fopen('file.txt''w');
    fwrite($fp$bleh);
    fclose($fp);
    ?>
    You're done. On the other hand, if you're doing it remotely, you'll want to do that code, then FTP put file.txt, and then delete the local file.txt I don't think you can open a connection and edit live on the server.. FTP clients support that only by downloading it (to a temp file), and then on close uploading it... it's not in the FTP protocol, as far as I know.

  4. #4
    SitePoint Enthusiast RahulKumar's Avatar
    Join Date
    Jul 2004
    Location
    Germantown
    Posts
    44
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Okay I ripped this from the PHP manual but I get a weird error:

    PHP Code:
    //ftp settings - set these!
    $ftp_server "bsa270-memphis.com";
    $ftp_user_name "****";
    $ftp_user_pass "*****";
    $destination_file "IP_Log.txt";

    //ftp writing process
    if ($file_enabled == TRUE){
    // set up basic connection
    $conn_id ftp_connect($ftp_server);

    // login with username and password
    $login_result ftp_login($conn_id$ftp_user_name$ftp_user_pass);

    // 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";
       }

    // upload the file
    $upload ftp_put($conn_id$destination_file$filenameFTP_ASCII);

    // 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); 

    Warning: ftp_close() expects parameter 1 to be resource, null given in C:\Program Files\Apache Group\Apache2\htdocs\ipftp.php on line 56

  5. #5
    SitePoint Zealot Selatos's Avatar
    Join Date
    Aug 2002
    Location
    USA
    Posts
    144
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    that means the connection failed, I believe. Add error_reporting(E_ALL); to the top and itll issue a warning or something if the connection fails(i don't know if !null equates to false.)

  6. #6
    SitePoint Member
    Join Date
    Nov 2004
    Location
    manila
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you must put ftp_close($conn_id); before the last closing brace.


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
  •