Asu Asu -4 years ago 133
PHP Question

How to upload all open files to remote host in NetBeans (PHP)

I have edited several dozens files in a wide range of directories and I first want to upload them to a test server, and then to the production server (different connections set up in NetBeans).

(Edit: For server-specific reasons I can't use version control for this either. I only have FTP access. Not even SFTP. And no shell.)

So, in NetBeans we can upload a single file or recursive directory easily by a keyboard shortcut or context menu.

In the past I used a keyboard shortcut to upload the current file, then CTRL+W, then repeat until all files are done. But since I want to upload to two servers, this isn't an option. Also, when there are many files it would be quite inconvenient any way.

Using NetBeans' synchronisation also does not seem to be an option, because in my source there are tens of thousands of files. An upload directory alone may also have over 10,000 files (which is the limit that FTP server is willing to serve, and I am not in a position to redesign the system to avoid having too many files in a single directory).

I suppose I could work out all directories with edited files and attempt to synchronise them instead of the whole source, but this is also not an easy task, given several dozen files opened (I'd have to hover over each tab and see which directory it is from). And even then NetBeans' synchronisation is quite a manual experience.

Could somebody suggest a semi-automatic (at least) method of uploading files that are open in the currently active tab?

I would also like to avoid having to compare complete contents of local and remote because of the remote having gigabytes of content.

Also some files on local are different from remote and must stay that way (server-specific configs). These are obviously not amongst the currently open files.

Answer Source

Note: this solution is for Windows and assumes the files to be uploaded are all open files in this project.

So, this is not the ideal solution I was looking for, but it solved my problem.

First, we can get the list of files that are currently open for the project by doing this (note: although this is not entirely the same as files open in a tab, but is sufficient for solving my problem, as I had a separate tab for all files related to this specific project any way):

  1. Open the NetBeans project folder
  2. In the project folder, open nbproject\private\private.xml
    It will have a list of files open for this project, e.g.:

  3. Copy it to a separate text file and cut off the path up to and including remote root (htdocs) level
    Don't forget to fix slashes e.g.:


    Now that we have the list of files, we can copy them including directory structure to a temporary location, from which we will upload them to FTP

  4. Create a batch file prepare-patch.bat with the following contents:

    @echo off
    SETLOCAL EnableDelayedExpansion
    for /F "tokens=*" %%A in ('type %1') do (
        set original_path=%~2%%A
        set destination_path=%~3%%A
        echo Copying `!original_path!` to `!destination_path!`
        echo f | xcopy /Y /Q "!original_path!" "!destination_path!"

    It takes 3 arguments:
    1) Path to the list of files
    2) Path to htdocs root
    3) Path to the temporary directory

  5. Use it like this:

    w:\prepare-patch.bat "D:\work\patched_files.txt" "w:\xampp\htdocs\" "w:\temp\"

Now the temporary directory contains all the files with complete folder structure:

w:\>dir /s /b w:\temp

You can connect to the FTP, navigate to htdocs root and simply upload-overwrite from this temporary directory.

Of course, this is a lot more work than it ideally should be, but it is still faster than uploading files one by one when you have a few dozen files.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download