Read and write files from a protected shared folder on another device - java

How to read and write files from a protected shared folder on another device using Java?
I'm currently working on a backup program which backups all the computers we use at home to a NAS system. This NAS has a shared folder which is used to store the backup files in. This shared folder is protected with a username and password.
I would like to read and write files to this system using Java. Reading and writing files is easy, the problem is though, it isn't possible to read and write files from this shared folder because user credentials are required. How to I login automatically on this shared folder with supplied user credentials using Java, before using this shared folder?
So, the problem doesn't have anything to do with the file path I should be using, or the way I should reach this folder. The problem I have is, that the Java program needs to login automatically on this shared folder with supplied user credentials before reading or writing any files from this external file system.

Related

Access file on a share(File server)

I want to access a file server that is not present in my network, but I have credentials of other domain that can be used to access the file.
How do I gain access to the file in share?
Is it possible to gain access to the file using a java program?
Operating System is Windows. I want to read the contents from .txt and .csv files present in the share and display it on a web page.
I used jcifs library to solve this. It works great.
You can use ftp protocol.
And also can make a map drive from share folder on your system. It's a simple solution.

Connect to a shared drive in java

I need to connect to a windows shared drive so I can make a directory and then some files in that directory. I am not sure how I would go about this. Can you use any built in classes for java?
If you map the drive onto your machine you should be able to access the drive with the normal filepath "(Drive Letter):/"
Depending on your network configuration you might also be able to use the filepath "\(Server name)\"

How to provide access to encrypted files without decryption complete?

I'm writing a small Java application similar to TrueCrypt, it is a container with encrypted user files.
There is a problem with access to encrypted files. At the moment, I'm using this approach:
1. When connecting the container completely decrypt all files in a common folder.
2. Mount folder as a drive.
3. Watch the events in a folder decrypt files using WatchService.
4. For example, when adding a new file is encrypted, and it is stored in the container.
5. After disconnecting the container delete all encrypt files and unmount folder.
I would like to find a solution that would allow to decrypt only the files that the user wants to use, such as providing the user access only to the names of the files, and when the user wants to use to decrypt only one file.
The requirements are: to use only native system file manager, don't write own file manager, a decision should be cross-platform.
At the moment, there is an idea to implement the FTP protocol, or WebDAV and mount it as a network drive.
Is there a simple and elegant solution?
One possibility would be to encrypt each file in the container separately. Encrypt the directory separately as well. When connected, just decrypt the directory file for the user to see. Other files are decrypted/encrypted as the user opens and saves them. Use a similar process for subdirectories if any are present.
This is more complex to run than encrypting the whole container in a single large encrypted file. It will also impose a delay on individual file access due to en/decryption.

how to prevent unsetting ReadOnly flag of a file using java?

I 've created a servlet to let users download a file . When the file is downloaded , I want it to be ReadOnly so that the user can't modify its content . So I've used the java.io.File class :
downloadFile.setWritable(false);
but I realized that the user can unset the read only flag after downloading the file .
What can I to prevent unsetting the read only flag?
I've created a servlet to let users download a file.
That servlet will be running on the web server. It's not running on the user's local computer - so it can't change anything about the user's local file system. Even your downloadFile.setWritable(false) won't operate on the user's local file system - the file will be saved by the browser, and the user gets to do whatever they want with it.
Even if you are running some app separately to your service, it would be not only hard, but pretty unfriendly to create a file which the user couldn't touch on their own system. You could try to run your app as a separate user, and give appropriate permissions to both the file and the directory it runs in - but then if the user has access to an administrator account, they'd still be able to override that.
As a user has downloaded your file, he can do anything with this file. If you are concerned about authenticity of the downloaded file, then consider data signing.
Sign your file using key, that is stored on the server and which is not available to end user.
To verify the file authenticity implement a servlet with functionality described in the link above.

where to keep the file path while hosting the java web app?

I have developed a website, one of its operation is to read and write data to text files stored at my local machine such as D://test.txt or C://file.txt, but now I am going to host my website at the external server, i mean over the internet use, i wonder where to keep these files that are associated with read and writing operations. At present I am getting an exception file not found if i am using my local machine location. For your information, I am using GlassFish server.
You will want to create a system property on Glassfish, which represents the file path and name. Then upload the file to that location of your choosing on the server where your website application is deployed.
Depending upon your needs, you may find it easier to deploy the file out with your application. Make sure the file is on the classpath, and you can load it using any number of ways.

Categories