7 Replies Latest reply: May 28, 2010 1:09 PM by 800389 RSS

    How to upload a file to two different servers?

    843790
      Hi All

      We have a JSP page in our web application where we allow user to upload a file. The file is saved on to the JBOSS application server's deploy folder. Now we have another server where we need to have copy of the same files uploaded by the user.

      We have two servers server A and server B. The web application is deployed on to both the servers. These two servers are part of the cluster, so whenever a user access the application he can go to either of the severs. Lets say he uploads a file on server A .

      Later when he comes back to the application and now say Server A is down. So Server B will server user requests. But in this case he will not get his uploaded file as it was uploaded on to the server A when he last accessed the application.

      So, we need to copy the file to server B also when he uploads to server A and vice-a-versa.

      How can we upload a file.copy to another server?

      Please help.

      Thanks
        • 1. Re: How to upload a file to two different servers?
          800389
          Couple of solutions:

          1) Write copy script. Whenever the file is uploaded, the script should be executed to copy the file on all remaining machine in cluster.
          2) Instead of storing the file on cluster server, store it on some common location say FTP server. This way, you don't need to worry about server down or new server is added into cluster. File will always be accessible to your application.
          3) Save the file in database instead of disk.

          Edited by: Adhir_Mehta on May 28, 2010 5:03 AM
          • 2. Re: How to upload a file to two different servers?
            843790
            Hi Adhir

            Thanks for the solutions.

            Separate FTP server for files sounds to be the best solution but as of now we can not have the separate FTP Server for files only. As well we can not make whole lot of changes now to save files into the db as there are already plenty of files uploaded by users on the live servers.

            So, what now we can do is to write code to copy the files to each server in cluster whenever a file is uploaded on any of the servers in the cluster.

            Is there any sample code to do this?

            We have a file upload utility class which uploads file on to the same server at specified location.
            • 3. Re: How to upload a file to two different servers?
              800389
              ashishjmeshram wrote:
              So, what now we can do is to write code to copy the files to each server in cluster whenever a file is uploaded on any of the servers in the cluster.
              As I mentioned, you can also explore the possibility of "script". Whenever new file arrives in folder, you can trigger the script to copy the file in remaining cluster servers.
              • 4. Re: How to upload a file to two different servers?
                843790
                How do we write such script?

                Any sample code will be highly appreciated.

                Thanks.
                • 5. Re: How to upload a file to two different servers?
                  800389
                  ashishjmeshram wrote:
                  How do we write such script?
                  If you are using linux machine, probably you can write shell script etc. However, I would suggest you to contact your system administrator to get more easy and sophisticated options.
                  • 6. Re: How to upload a file to two different servers?
                    843790
                    What about using a networked file-system, that is, a shared folder?

                    Clusters are there to help avoid a single point of failure, that is, if a machine falls out, the other does the production.
                    We are keenly searching for a way to introduce a single point of failure into the architecture :-(
                    • 7. Re: How to upload a file to two different servers?
                      800389
                      BIJ001 wrote:
                      What about using a networked file-system, that is, a shared folder?
                      Any shared location should be ok. Thats why I suggested FTP earlier.
                      We are keenly searching for a way to introduce a single point of failure into the architecture :-(
                      Because we don't learn from mistakes and continues unless it burst again ;-)