Is there any way using PHP and MySQL to download a remote data txt file and put it into a table?

I can get it to work if I download the file to my drive first, but I need to figure out how to get the info to my machine from the remote one, and have it done automatically.

Thanks for any help.

    I'm working on something similar. I have a few parts working but not all the answers.

    Here's some code that I use to get the remote text file onto my server. I suppose you could run this using CLI and a cron job but I am still trying to figure that out.

    <?php
    $ftp_server = "0.0.0.0"; //your ftp addr that has the file goes here
    $ftp_user_name = "username";
    $ftp_user_pass = "password";
    $local_file = "data/file.txt";
    $remote_file = "file.txt";
    // 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\n";
       }
    
    // upload the file
    $dnload = ftp_get($conn_id, $local_file, $remote_file, FTP_BINARY);
    
    // check upload status
    if (!$dnload) {
           echo "FTP download has failed!";
       } else {
           echo "Downloaded $local_file as $remote_file ";
       }
    
    // close the FTP stream
    ftp_close($conn_id);
    ?> 

    Beyond this, I tried scripting the file to upload into a database without much luck. I did find a thread that claims to have resolved just that problem but without the detail. I posted a messagae to please share the solution. Here is that post:
    http://www.phpbuilder.com/board/showthread.php?t=10284620

    Hope that helps

      Also, if you've go fopen url functions enabled, you can do things like:

      $fp = fopen("http://myserver.com","r");
      $file = fread($fp,1000000);

      to get it.

      Works with [url]ftp://name:password@server.com/path/file[/url] as well.

        Write a Reply...