#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    6
    Rep Power
    0

    Ftp_get doesn't download to computer


    Hi all,

    first time on here. I'm stuck and may just be understanding ftp_get () all together. Please help me.

    I understand that ftp_get() should be able to download a file from the server (mine is on hostgator.com) to a folder on the local cpu. Can this be created in a chron job and done weekly without a person clicking or opening a webpage?

    I seem to have it all set up to work EXCEPT I'm unsure how to set the file path to the local cpu folder. It saves it to the same folder that the .php file calling it is located instead of on my computer (as noted on many websites it will do but nobody states how to set it to your own cpu drive)?

    Below is my code... Where is my thought process failing?

    PHP Code:
    <?php         $local_file "/Users/name/Driver_record.zip";//working from a mac currently
    $server_file "/folder1/folder2/filename.csv";                 //-- Connection Settings 
    $ftp_server "ip address";
    $ftp_user_name "xxxx";
    $ftp_user_pass "xxxx";

     
    // 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);// try to download $server_file and save to local_file
    ftp_pasv($conn_idTRUE);

    if (
    ftp_get($conn_id$local_file,$server_file,FTP_BINARY)){
                echo 
    "Successfully written to $local_file\n";         } else {
                 echo 
    "There was a problem\n";
    }
    // close the connection
    ftp_close($conn_id);
    ?>
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    11
    Rep Power
    0
    The thing is, you write the file on the server and not on your computer (or are you executing the PHP file on your computer?). You would need to have acces to your computer from the server and your computer would have to be online everytime the cron job is executed on the server. Is that really what you want?
  4. #3
  5. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    13,965
    Rep Power
    9397
    "How to set it to your own CPU drive"? What?

    Your code is correct so far. Are you sure your script has permissions to write to /Users/name? Have you set error_reporting=E_ALL and display_errors=on in your php.ini, so that if there are any errors you'll see them?
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    6
    Rep Power
    0
    Thanks for the questions,

    The executing php file with php_get() would run as a cron job on the server containing the files to be downloaded. I want to download the file to my computer, say at 2am once a week from the hosting server.

    I was not seeing how to set the path from the server ftp to my computer. Simply stating "C://folder/filename.csv" wouldn't state which computer in the world it would be downloading to. So i was thinking I would have to use an ip address as well.

    I already have the file created on my server. I just wanted it downloaded to a folder on my computer without having to 'click', load a webpage, or any other action on my part.

    I'm now looking into ftp_put() instead of 'getting' the file from the hosting server. I think i might have to PUT the file from one server folder to a folder on the second ftp server I have.

    If this is the case; which server would be local and which would be remote? I'm guessing:
    • local_server = server writing the file to

    • remote_server = server reading the file


    I hope this makes sense. If not, please let me know where my thought process is wrong.

    Thanks,
    BiggBrawler
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 2003
    Posts
    3,350
    Rep Power
    594
    I think you are over complicating this. Why not share out the target directory on your computer and give your server permission to map it? Then simply copy to \\yourcomputer\yourshareddirectory\filename.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    6
    Rep Power
    0
    I.T. Dept. says to many holes in the firewall for that. Can not connect external linux server to internal file share.
  12. #7
  13. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,846
    Rep Power
    6351
    Are you trying to download this file to the USER'S machine (the machine running chrome/firefox/whatever and viewing your site) or to YOUR machine (the machine running apache and PHP)?
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
  14. #8
  15. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    6
    Rep Power
    0
    I'm using a php script on hostgator shared server and want to download a file using ftp to a startlogic shared server.
  16. #9
  17. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 2003
    Posts
    3,350
    Rep Power
    594
    If you have firewalls in the way, you probably will have to do a pull from the target rather than a push from the source.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  18. #10
  19. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    6
    Rep Power
    0

    Thumbs up


    Originally Posted by gw1500se
    If you have firewalls in the way, you probably will have to do a pull from the target rather than a push from the source.
    You saved me so much grief. You're correct.
    I needed to pull (ftp_get) FROM the server with the file instead of trying to push (ftp_put) TO the server I wanted it on.

    Thank you so much!
  20. #11
  21. Mad Scientist
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Oct 2007
    Location
    North Yorkshire, UK
    Posts
    3,661
    Rep Power
    4123
    You CANNOT download files over FTP to your clients machine using the php functions you have there

    FTP uses the client-server model; and the ftp_functions are for building/working with the client side of the model. Your website users will not be running an ftp server for you to 'upload' to

    If you want to download files to YOUR own computer then get yourself a copy of filezilla or cyberduck and then look for ways to schedule that.

    Also, please see this thread and, specifically, my reply
    I said I didn't like ORM!!! <?php $this->model->update($this->request->resources[0])->set($this->request->getData())->getData('count'); ?>

    PDO vs mysql_* functions: Find a Migration Guide Here

    [ Xeneco - T'interweb Development ] - [ Are you a Help Vampire? ] - [ Read The manual! ] - [ W3 methods - GET, POST, etc ] - [ Web Design Hell ]

IMN logo majestic logo threadwatch logo seochat tools logo