Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    Feb 2008
    Location
    Cork- Ireland
    Posts
    16
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Smile ftp_fget 'path' problem

    I am trying to copy file from remote UNIX server to folder on 'C drive' on PC that is running webserver. I can copy to folder in htdocs on webserver, but what is the correct syntax to set path for download to folder 'POS' on C drive. The following path does not work...

    This is my personal project - not 'commercial' (hi Aero! )

    PHP Code:

    // path to remote file
    $remote_header_file 'PO'.$ponumber.'H';
    $remote_detail_file 'PO'.$ponumber.'D';


    // path to local file
    $local_file 'C:/POS';


    // open file to write to
    $handle fopen($local_file'w');


    // download $remote_header_file and save it to $handle

    if (ftp_fget($conn_id$handle$remote_header_fileFTP_ASCII0)) {
     echo 
    "$remote_header_file successfully written to $local_file\n at $time";
    } else {
     echo 
    "There was a problem while downloading $remote_header_file to $local_file\n";


    Wow - I did'nt know that !!!

  • #2
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Are you getting any errors? Run this function by it self outside of the if statement and see what it returns
    PHP Code:
    ftp_fget($conn_id$handle$remote_header_fileFTP_ASCII0); 
    I don't know if it matters but you may have to switch your slashes though I think windows does both.
    PHP Code:
    $local_file 'C:\POS'
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #3
    New Coder
    Join Date
    Feb 2008
    Location
    Cork- Ireland
    Posts
    16
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Thanks Aero -

    I have now amended the code slightly, and the two files are being saved fine in 'C:/POS'. My only problem now is that they are being saved by the string name, i.e., $remote_header_file and $remote_detail_file.

    I will have to keep tinkering... When I echo the string name, it prints the correct file name, ie. PO51234H and PO51234D.... odd!


    PHP Code:
    // path to remote file
    $remote_header_file = 'PO'.$ponumber.'H';
    $remote_detail_file = 'PO'.$ponumber.'D';
    $local_file_header = 'C:/POS/$remote_header_file';
    $local_file_detail = 'C:/POS/$remote_detail_file';


    // open file to write to
    $handleH = fopen($local_file_header, 'w');

    // download $remote_header_file and save it to $handle

    if (ftp_fget($conn_id, $handleH, $remote_header_file, FTP_ASCII, 0)) {
     echo "$remote_header_file successfully written to $local_file\n at $time";
    } else {
     echo "There was a problem while downloading $remote_header_file to $local_file\n";

    }

    ?>

    <html>
    <br></html>

    <?php        

    $handleD 
    fopen($local_file_detail'w');

    // download $remote_detail_file and save it to $handle            

    if (ftp_fget($conn_id$handleD$remote_detail_fileFTP_ASCII0)) {
     echo 
    "$remote_detail_file successfully written to $local_file\n at $time";
    } else {
     echo 
    "There was a problem while downloading $remote_detail_file to $local_file\n";

    }

            
    ftp_close($conn_id);
    Wow - I did'nt know that !!!

  • #4
    New Coder
    Join Date
    Feb 2008
    Location
    Cork- Ireland
    Posts
    16
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Question

    PHP Code:

    <?php
    // path to remote file
    $remote_header_file 'PO'.$ponumber.'H';
    $remote_detail_file 'PO'.$ponumber.'D';
    $local_file_header 'C:/POS/$remote_header_file';
    $local_file_detail 'C:/POS/$remote_detail_file';


    // open file to write to
    $handleH fopen($local_file_header'w');

    // download $remote_header_file and save it to $handle

    if (ftp_fget($conn_id$handleH$remote_header_fileFTP_ASCII0)) {
     echo 
    "$remote_header_file successfully written to $local_file\n at $time";
    } else {
     echo 
    "There was a problem while downloading $remote_header_file to $local_file\n";

    }

    ?>

    <html>
    <br></html>

    <?php        

    $handleD 
    fopen($local_file_detail'w');

    // download $remote_detail_file and save it to $handle            

    if (ftp_fget($conn_id$handleD$remote_detail_fileFTP_ASCII0)) {
     echo 
    "$remote_detail_file successfully written to $local_file\n at $time";
    } else {
     echo 
    "There was a problem while downloading $remote_detail_file to $local_file\n";

    }

            
    ftp_close($conn_id);
    Wow - I did'nt know that !!!

  • #5
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    You need to use double quotes if you want the variables to parse. Try this
    PHP Code:
    $local_file_header "C:/POS/$remote_header_file";
    $local_file_detail "C:/POS/$remote_detail_file"
    or you can do this
    PHP Code:
    $local_file_header 'C:/POS/'.$remote_header_file;
    $local_file_detail 'C:/POS/'.$remote_detail_file
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #6
    New Coder
    Join Date
    Feb 2008
    Location
    Cork- Ireland
    Posts
    16
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Aero.

    I COULD KISS YOU!

    You dont know how much you have helped me there - I would have been messing about for ages with that...

    Your a diamond!

    chat laters -

    Dave
    Wow - I did'nt know that !!!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •