FTP client class is not connecting
further to this link i just want to know to upload a file in specific directory location for example there is a cross reference in IP and then further a library in cross reference then how would i upload file in library or in precise how would i get connected to ip/cross reference/library for location where i need to upload a file. here i want to mention that i successfully get connected to IP till now.
The constructor of FTPHTTPClient doesn't appear to take a path in the constructor, its just the hostname/ip. Also, most FTP clients use / and not \ as the path separator.
The JavaDoc for FTPClient shows there is a method changeWorkingDirectory(String pathname), which I am guessing is what you want to do.
Related
I'm currently developing a Tracking System with JavaFX and MySQL as database that is kept in a server. My application is used within a network and allows users to upload and download pictures and several types of document.
My question: What is the best way to send and retrieve files to a server within a network? And should I store those files in MySQL or just their paths in MySQL? If only files' paths, do I need FTP or other techniques? I need detail answer because it is my first time to develop such application.
Edit: I want to store data in a server. I build this application for client machines so that clients can keep documents in the server and they can access their files from any machines... I have no idea for how to transfer files from client machines to server. Please help me!
You should use socket programming like what is at following link:
http://www.rgagnon.com/javadetails/java-0542.html
.But if you are using Java7, Files is the best one instead of BufferedInputStream or FileInputStream (No extra library require):
/* You can get Path from file also: file.toPath() */
Files.copy(InputStream in, Path target)
Files.copy(Path source, OutputStream out)
I'm working on an android app, and I can actually get a list of all my files, but can't use the URL to open a file from the list, I also tried to open from InputStream, but this does not work.
What I want to do is something like ES File Explorer does, I know they use JCIFS library, and that when you open a file (an MP3 for example), they make some kind of Tunnel with sockets, that reads the file and pass it to the propper app in an HTTP format.
Example:
If my nas file path is:
smb://My_IP_Address/SharedFolder/Media/MyMusic.mp3
ES File Explorer send an URL like this:
http:// 127.0.0.1:59777/smb%2FMy_IP_Address%2FSharedFolder%2FMedia%2FMyMusic.mp3
Sorry, I want to use comment instead of answer, but I don't have enough reputation...
What I found on ES Explore or other same app, they seemed not only use JCIFS , but also use nanoHTTPD...
They transfer the nas file to samba file, then use nanoHTTPD as a Streaming server to serve the multimedia files...
There got many sample on the web, here a discussion =>
How to serve a file on sdcard using NanoHTTPD (inside Android)
Hope this can help you...
It's off course doable but kind of tricky. Your app must act as a server, reading an input stream from the samba share, streaming it to a third party application like a music player if we are talking about a mp3 file.
You'll find details here : Android ServerSocket programming with jCIFS streaming files
Say I have an image file that is located in http://a.com/example.jpg
Then I have a network storage called http://b.com/
Using java, how can I move example.jpg directly to b.com?(Kind of like P2P??)
EDIT
I think I should explain a little bit more.
I want to move file example.jpg to b.com without downloading the file.
Normal approach will be
Open connection to a.com
Download example.jpg to my computer (either memory or disk)
Open a new connection to b.com
Upload the example.jpg to b.com
However, I think this involves unnecessary work.
What I want is this
Open connection to b.com
Without opening connection to a.com, upload example.jpg directly to b.com (I think this is the part where I thought of P2P)
Is there any way that I can do this?
There is no general way to do what you ask merely with HTTP. You would have to have specific support for such operations on the server hosting your network storage, such that you can request it to download URLs directly.
You can get the image using HttpClient from a.com and then upload it to b.com. How do you upload it b.com depends on what you have there.
To be able to do this without downloading the file you will need specific support on b.com. That specific support will be a service on b.com where you send a "download" request and the server will download the file itself from a.com.
We have a web application that allows user to download a zip file from a web server. We just provide dummy iframe source to the full URL of zip file on web server. This approach would allow end user to use browser controls which allows the user to open or save the zip to user's local machine.
We have a requirement that the zip file is automatically extracted and save to a specific location on user's machine. Any thoughts on how this can be achieved?
Thanks.
I highly doubt that you'll be able to do that. The closest you're likely to get is to generate a self-extracting executable file (which would be OS-dependent, of course).
I certainly wouldn't want a zip file to be automatically extracted - and I wouldn't want my browser to be able to force that decision upon me.
Short answer is I don't believe this is possible using the simple URL link you've implemented.
Fundamentally the problem you have is that you have no control over what the user does on their end, since you've ceded control to the browser.
If you do want to do this, then you'll need some client-side code that downloads the zipfile and unzips it.
I suspect Java is the way to go for this - Javascript and Flash both have problems writing files to the local drive. Of course if you want to be Windows only then a COM object could work.
Instead of sending a zip file why don't u instruct the web server to compress all the web traffic and just send the files directly?
See http://articles.sitepoint.com/article/web-output-mod_gzip-apache# for example.
I'm trying to create a zip file from a directory in Java, then place that file on a remote server (a network share). I'm currently getting an error because the Java File object cannot reference a remote location and I'm not really sure where to go from there.
Is there a way to zip a directory in Java to a remote location without using the File class?
Create the ZIP file locally and use either commons-net FTP or SFTP to move the ZIP file across to the remote location, assuming that by "remote location" you mean some FTP server, or possibly a blade on your network.
If you are using the renameTo method on java.io.File, note that this doesn't work on some operating systems (e.g. Solaris) where the locations are on different shares. You would have to do a manual copy of the file data from one location to another. This is pretty simple using standard Java I/O.