Copying file from hosted remote sever to local machine

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ian Davies

    Copying file from hosted remote sever to local machine

    Hello
    I am trying to use php to automate the copying of a file from my remotely
    hosted directory to my computer. I have put together the following but it
    will only do the copying from one directory to another on the remote server.
    Reading the postings on these functions they suggest that it can be done but
    it appears to be the case if your are hosting your site on the same machine
    you want to copy the files to. Does anyone know if there are functions in
    php to do the transfer from remote server to my machine or if the code below
    will acheive this with modification?


    Ian



    <?php
    $ftp_server = "xxxxxxxx";
    $ftp_user = "xxxxxxx";
    $ftp_pass = "xxxxxx";
    $local_file = 'myfile.txt';
    $server_file = 'myfile.txt';

    // set up a connection or die
    $conn_id = ftp_connect($ft p_server) or die("Couldn't connect to
    $ftp_server");

    $login_result = ftp_login($conn _id, $ftp_user, $ftp_pass);

    // check connection
    if ((!$conn_id) || (!$login_result )) {
    die("FTP connection has failed !");
    }

    // try to change the directory to myfilesdirector y
    if (ftp_chdir($con n_id, "myfilesdirecto ry")) {
    echo "Current directory is now: " . ftp_pwd($conn_i d) . "\n";
    } else {
    echo "Couldn't change directory\n";
    }

    if (ftp_get($conn_ id, $local_file, $server_file, FTP_BINARY)) {
    echo "Successful ly written to $local_file\n";
    } else {
    echo "There was a problem\n";
    }

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



  • Steve

    #2
    Re: Copying file from hosted remote sever to local machine

    [color=blue]
    > I am trying to use php to automate the copying of a file from my remotely
    > hosted directory to my computer. I have put together the following but it
    > will only do the copying from one directory to another on the remote server.[/color]

    I'm not sure if I've understood what you are doing so bear with me. The
    code is fine, but it has to be executed on the /local/ machine, not the
    /remote/ machine. The remote machine has the FTP server which the local
    machine communicates with using the FTP protocol.

    ---
    Steve

    Comment

    • larry@portcommodore.com

      #3
      Re: Copying file from hosted remote sever to local machine

      I don't think you will get it to work, The best you can probably get
      is to make it offer a file to you (ala download), but since the remote
      server does not control your computer it can't really make it do
      anything like automatically accept a file - unless you had some sort of
      special client plugin to allow the server to do such things. (ala
      software update)

      If you are doing a bunch of files you can pack them up on the server
      calling some zip app and then ask the client to download them.

      Comment

      • Ian Davies

        #4
        Re: Copying file from hosted remote sever to local machine

        Eureeka
        Ive found a solution. Visual basic offers functions that use the 'Internet
        Transfer Control' which can communicate with remote server and manipulate,
        put and get files to and from it as well as other interesting things.
        If anyone is interested do a search on Microsoft website for 'Internet
        Transfer Controls' Here is a link to an excellent downloadable example which
        pretty much does everything I need



        Happy programming
        Ian

        <larry@portcomm odore.com> wrote in message
        news:1130475947 .597467.198170@ g43g2000cwa.goo glegroups.com.. .[color=blue]
        > I don't think you will get it to work, The best you can probably get
        > is to make it offer a file to you (ala download), but since the remote
        > server does not control your computer it can't really make it do
        > anything like automatically accept a file - unless you had some sort of
        > special client plugin to allow the server to do such things. (ala
        > software update)
        >
        > If you are doing a bunch of files you can pack them up on the server
        > calling some zip app and then ask the client to download them.
        >[/color]


        Comment

        • C.

          #5
          Re: Copying file from hosted remote sever to local machine

          So I guess:

          file_put_conten ts($localfilena me,
          file_get_conten ts("ftp://{$user}:{$passw ord}@{$host}{$r emote}"));

          doesn't work?

          C.

          Comment

          • Chung Leong

            #6
            Re: Copying file from hosted remote sever to local machine


            Ian Davies wrote:[color=blue]
            > Hello
            > I am trying to use php to automate the copying of a file from my remotely
            > hosted directory to my computer. I have put together the following but it
            > will only do the copying from one directory to another on the remote server.
            > Reading the postings on these functions they suggest that it can be done but
            > it appears to be the case if your are hosting your site on the same machine
            > you want to copy the files to. Does anyone know if there are functions in
            > php to do the transfer from remote server to my machine or if the code below
            > will acheive this with modification?[/color]

            Simple, old fashioned way of automating a task:

            ftp < commands.txt

            Comment

            Working...