PHP FTP functions.....

Discussion in 'Web Design and Development' started by bigandy, Apr 10, 2007.

  1. bigandy macrumors G3

    bigandy

    Joined:
    Apr 30, 2004
    Location:
    Murka
    #1
    I've got a script that uploads a file, but then, after processing, it needs to FTP it to another server.

    The script I've got is as follows. What am I missing, as the php file doesn't actually finish loading if this part of the file is there. :(

    Code:
    $ftp_server = "www.server.net";
    $ftp_user_name = "user@server.net";
    $ftp_user_pass = "password";
    $source_file = "/home/user/public_html/directory/$exefile.ext";
    $destination_file = "$exefile.ext";
    
    echo $conn_id = ftp_connect($ftp_server); 
    
    echo $login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass); 
    
    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";
        }
    
    echo $upload = ftp_put($conn_id, $destination_file, $source_file, FTP_BINARY); 
    
    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);
    Help much appreciated :eek:

    edit: the directory should be set by the custom user for this FTP upload script.. but do I need to set that anyway?

    also, does it have a limit? is that why it's messing up? can i run FTP from the shell using exec? i know that the linux shell ftp needs user input, can i emulate this? it doesn't work if i do this:

    Code:
    ftp www.server.net user@server.net password send /home/user/public_html/directory/file.ext file.ext exit
    because it needs a carriage return between each command sent :(
     
  2. Winterfell macrumors regular

    Joined:
    Apr 3, 2007
    Location:
    Tulsa, Oklahoma
    #2
    Can you post the output of the script where it fails? Is there any output?
     
  3. bigandy thread starter macrumors G3

    bigandy

    Joined:
    Apr 30, 2004
    Location:
    Murka
    #3
    There isn't any output... I'll post what detail I have soon, I'd kinda given up hope on hearing any replies! :eek:
     
  4. Winterfell macrumors regular

    Joined:
    Apr 3, 2007
    Location:
    Tulsa, Oklahoma
    #4
    Try putting
    PHP:
    error_reporting(E_ALL);
    at the very top of your PHP script (right after the very first <?php opening tag). That will tell PHP to output everything: errors, warnings, you name it. Maybe that will give us something more to go on. :)
     

Share This Page