Reading file on client machine from server - java

I have added functionality which will enable the user to attach a file from web page.
and this file will be sent as an attachment to another user.
When I try this on my local machine it works fine.
I deployed the application on the server.
And when I am trying to attach a file its throwing FileNotFoundException.
Kindly help.

You seems to be reading file system assuming that client is always on server.
Server and Client are different things. Client may be / May not be [all most all the time] on server. You need to upload file then read..
If you can read client's flle system this easily, then we might not have coined the word security

Related

How to ensure authentication while designing a system for downloading files?

How will I ensure the authenticity of users while downloading a file? I am trying to figure out how to design such a system so that files can be securely downloaded with resume/pause capabilities?
Currently, I tried serving the files through my java-middleware so when client requests for the assets, the client will send the jwt token with the request which will ensure authenticity and then java-middleware will connect with the file server which will send back to the response the middleware which in turn server the file to the client.
But the download is consistently failing and not I am not able to provide resume/pause functionality.
I thought of directly serving the files through SFTP server to the client but then how to ensure the request is authenticated is not clear to me.
Can someone guide me what and how should the above download be achieved?
EDIT:
The file downloaded is not static it is dynamically generated per user, and contains meta-data about the user.
To be more precise the file to be downloaded is a .msi installer which should be linked to an account to be installed on the system. Hence I have to package the downloaded installer with the user-authorization account token so that when user double clicks on it should be installed as per user context .

File grabber from FTP

I have a file that changes every day for my website and I want to make a program that takes it from the FTP server and either downloads it to my phone or my laptop.
How would I go about making this and what code do I use?
A few options not already mentioned:
If you have access to the ftp server, a cron job could email the file to you each day.
You could create a web page populated with the data, using jsp, php, or servlet etc. to read the file from disk.
If you're familiar with rsync, you could simply rsync the file to your laptop
Sync the file using Dropbox

Java: Listen to directory change on a remote Linux server

I have a Spring web application which triggers a SAS job on a remote Linux server, the SAS job will generate a result file on the remote server upon finished. I need to display the result on my Spring application, so I want to create a listener for the directory changes on the server.
I have being looking at the java.nio library, but it looks like it only works local directories. Any ideas other than keep pinging the server through ssh? Thanks!
You might use FTP from org.apache.commons.net.ftp
Using FTP (or any other Java FTP library), you only need to check for the content on the remote directory.
If the directory supposedly is always empty, then when the first file appears your process will be triggered.
If the directory is not always empty, you might need to implement something to control which files are new, and which are not.
Please let me know if you need further assistance.

File upload on server

I have created an applet which creates a file on running it. But when I run my applet via server, it fails.
Is there any possible way to create a file on server with applet?
EDIT:I am creating a sound record applet which works fine when I run the applet in browser locally.It actually creates a file of recorded sound,but when I run the same applet on server,it does not create file.Is it because the server does not allow you to do so?
Is there any possible solution so that the file can be created?
File objects always point to a location (that may not exist) on the client machine.
To store something on a server, it would require some server side functionality to accept the bytes and create a (server-side) File. That might be done with PHP, servlets/JSP, ASP etc. Once the server-side is organized to accept the bytes, the applet can connect to it and push the sound recording through.
Java Applets are run on the client machine. Once you invoke the page containing an applet, the applet gets downloaded to the client's machine and runs. Hence it will not get access to the server.

OpenPeak Flash app XMLSocket Security Problem

We're trying to create an app for OpenPeak. The Flash app will act as a client to a Java server on another computer on another domain.
The Flash app client connects via XMLSocket. The Java Server uses ServerSocket to receive a request and send back a message.
In order to trust the server, the Flash client needs a socket master policy file to tell it that the server comes from a trustworthy domain. According to an article on Adobe, when a connection has succeeded, the Flash client automatically requests the cross-domain policy or socket master policy file on port 843.
Still, even when we implement it according to the tutorials and recommendations we have read, the Flash client continues to throw the following security error:
SecurityErrorEvent
type="securityError" bubbles=false
cancelable=false eventPhase=2
text="Error #2048"
We've tried logging the policy file request during testing to see if there was any call made to port 843. There was not.
Interestingly, even without a policy file, the Flash client still manages to send the first data message to the server successfully. It's just when the server tries to send back a reply that the entire thing hangs for about 10 seconds before the security error above is displayed.
Any ideas / suggestions?
In order for flash to access another domain you'll need a crossdomain.xml file, For this specific need you will probably have to specify a custom URL. Here is the code you need to do that:
flash.system.Security.loadPolicyFile("{Url to my crossdomain.xml file on the SSL virtual root}");
Here is a sample file which disables flash's "Same Origin Policy" protection for the domain that is using this file. Limiting this access to specific domains is highly recommended, but this is not always possible for some apps.
<?xml version="1.0"?>
<!DOCTYPE cross-domain-policy SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd">
<cross-domain-policy>
<allow-access-from domain="*.*" secure="false" />
</cross-domain-policy>
To debug this I would use TamperData to make sure flash is actually downloading the crossdomain.xml file. If you need to debug rtmp or some other non-http protocol then you'll have to use Wireshark.

Categories

Resources