Copy directory to another on site

Asked

Viewed 259 times

1

I have a site in PHP and Javascript. I set a button with the following function (found on the internet, called wrench.copyDirSyncRecursive):

function atualizaIR(){
    dir1 = '201.7.201.173/Documentos/Teste1';
    dir2 = '201.7.201.173/Documentos/Teste2';
    wrench.copyDirSyncRecursive(dir1,dir2);
    alert('IRs atualizados!');
}

Since the function (which is attached to a button I created on the page) should copy all the contents of the directory Teste1 to the directory Teste2.

I know there are several ways to make this copy of files, but I still haven’t been able to get the most efficient one that worked for this site of my client. In addition, the folder dir1 may be on a machine hard drive C with that IP, while the folder dir2 may be on a hard disk D, on the machine of that same IP.

Is it too hard to do?

editing

I did it as follows. In the JS file, it has this function:

function atualizaIR(){
$.ajax({
      async: true, 
      cache:false, 
      url: '[:raiz]consultaRendimentos/atualizaIR',
      dataType: 'json',      
      type: 'POST',
      success: function(data) {
          alert('IRs atualizados!');
      }
});
}

And in the Controller file, I did it as follows (based on w3schols.com):

public function atualizaIR(){
    // connect and login to FTP server
    $ftp_server = "http://201.7.201.173/";
    $ftp_conn = ftp_connect($ftp_server) or die("Could not connect to $ftp_server");
    $login = ftp_login($ftp_conn, $ftp_user, $ftp_password);

    $local_file = '../Documentos/Teste1/';
    $server_file = '../Documentos/Teste2/';

    // initiate download
    $d = ftp_nb_get($ftp_conn, $local_file, $server_file, FTP_ASCII);

    do{
        // do whatever you want
        // continue downloading
        $d = ftp_nb_continue($ftp_conn);
    }while ($d == FTP_MOREDATA);

    if ($d != FTP_FINISHED)
    {
        echo "Error downloading $server_file";
        exit(1);
    }

    // close connection
    ftp_close($ftp_conn);
}

But it didn’t work. Inside my server, the Teste2 pro Teste1 files were not copied or vice versa. I must be forgetting a lot for this copy of files to happen.

  • Copy directories with JS??? Edit: Now I see that this is Node.js. If you have knowledge in Node, go ahead, if not, I suggest PHP itself

  • I think this will help if it is in nodejs https://www.npmjs.com/package/ncp. If it is in javascript and php the best thing to do is with AJAX.

  • You get inside the method atualizaIR in PHP? Do a debug by placing a breakpoint within the method, or simply do a echo "Teste"; die(); and see in Chrome, for example, the result of POST Request using the console. The way it is in the question, will only do a POST to the server but will not enter into the method atualizaIR, unless the class has the same name, since in PHP5 it is still possible to have the constructor method with the same class name.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.