ftp_get: what goes wrong?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • cxian
    New Member
    • Jan 2007
    • 4

    #1

    ftp_get: what goes wrong?

    Hi all,

    I am trying to download files from a remote with the use of ftp_get.
    Somehow, the script always return to false.

    Here's what I got:

    [php]
    $conn_id = ftp_connect($ft p_host);
    $login_result = ftp_login($conn _id, $ftp_username, $ftp_password);

    if ((!$conn_id) || (!$login_result )){
    echo "FTP connection has failed!";
    echo "Attempted to connect to $ftp_host for user $ftp_username";
    exit;
    } else {
    echo "Connected to $ftp_host, for user $ftp_username";

    //change directory
    $ftp_chdir = ftp_chdir($conn _id,$remote_pat h);
    //retrieves files in the directory
    $file_slist = ftp_nlist($conn _id,$remote_pat h);
    //open local directory
    $dir_opn = opendir($local_ path);

    //get all the remote files
    foreach ($file_slist as $file_s) {
    $ftp_get = ftp_get($conn_i d,$local_path.$ local_file,$rem ote_path.$file_ s,FTP_ASCII);
    }

    //close dir
    closedir($ftp_c hdir);

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

    } //else
    [/php]

    Do I set the right parameters?


    Thanks in advice!
  • ronverdonk
    Recognized Expert Specialist
    • Jul 2006
    • 4259

    #2
    It looks okay, as long as you are really sure that all the other steps were completed correctly. Therefore myou should test the result of each function performed.
    Since ftp_chdir() is supposed to throw its own php error in case of failure, I advise you to test the results of your commands, because there could be the root of the problem. Adapt the following commands by capturing any possible errors:

    [php]if (!$ftp_slist)
    die ("ftp_nlist failed");

    if (!$dir_opn)
    die ("open_dir failed");[/php]
    Ronald :cool:

    Comment

    • cxian
      New Member
      • Jan 2007
      • 4

      #3
      Okay, there should be some error there.

      Thank you very much.

      Comment

      Working...