NetBeans: keeping current versions of files from a remote server via ssh

    Good day,% habrauser%!

    Anyone who works in this wonderful IDE, sooner or later, wonders: “Why isn’t there a simple, seemingly, thing - automatic file synchronization from a remote server !?”.

    In the project settings and in NetBeans settings there is a checkmark “Enable automatic scanning of source files”, which should solve this problem, but there was no positive effect from it.

    Once, due to the fact that NetBeans simply overwrites the files on the server, those that are saved in the project, the author lost several hours of work, forgetting to update the project. After this annoying misunderstanding, the thought of the incorrectness of the situation did not leave me. As a result, a way was born, unfortunately, I can’t integrate it into NetBeans itself, since I don’t know java, and if I integrate it, it’s not like that, but using the built-in diff tools.

    The method that was born is more like a crutch than a good solution to the problem, however, it does its job, like any other crutch. The first thing that came to mind is the rsync + bat + scheduler, but this black window that appears every few minutes did not bring joy, began to look for alternative ways and this is what happened:

    We will need

    for windows:

    for linux
    , depending on the shell of the operating system, set:
    • ssh
    • rsync
    • cron

    Common to Winsows and linux

    We create a sync.list file in the project folder (it can be called whatever you like, the main thing is not to forget to specify the corresponding name in the --files-from parameter) The

    file contains a list of synchronized directories. Particular attention should be paid to the fact that the directories inside should be relative , that is, if the project on the server is in the / sites / site1 folder, and we want to synchronize the / sites / site1 / public and / sites / site1 / app folders, then in the file you just need to write

    Each directory with a new line. All paths will be paved relative to the one specified in the rsync parameters, this behavior can be changed using the command flags.

    You can read about crontab settings, for example, here , about rsync settings, here


    • download and install nnCron
    • in the program folder we find the file and open it with any text editor
    • at the end of the file, add the following task:
      #( sync
      Time: */10  * * * * *
              var WshShell = WScript.CreateObject("WScript.Shell");
              WshShell.Run("C:\\cygwin\\bin\\rsync.exe -uptrzc -e 'ssh -i /cygdrive/d/id_rsa' --files-from=/cygdrive/d/NetBeansProjects/proj/sync.list login@server:/path /cygdrive/d/NetBeansProjects/proj/");


    • We open / etc / crontab with any text editor (for this you need sudo or root)
    • add task
       */10  * * * * *  user rsync.exe -uptrzc -e 'ssh -i /pathToKey/ssh_key' --files-from=/NetBeansProjects/project/sync.list login@server:/pathToProjectOnServer /NetBeansProjects/project/

    That's all. If your project does not use ssh, but ftp or another protocol, you can use the appropriate programs for this.

    Thank you for attention!
    Suggestions and suggestions are welcome!

    Also popular now: