Scourge Bermuda wrote:I' ve tried, it works with a file on remote machine at network. The exception is pointing your credentials on the remote machine. Do you have access to write on file?
Apparently not, as the exception indicates the problem is an authentication issue. And java.io.File is not going to help you with that. Enter JCIFS. Instead of using a FileOutputStream you create an SmbFile with the right credentials, then use its getOutputStream() method.
thanks ulf for the reply.Could you suggest some article relating to JCIFS that would help me to complete my job at the earliest?I have never used it before so highly confused.
Joined: Mar 22, 2005
I'm not aware of any introductory articles, although I'm sure they exist; searching for "jcifs introduction" or some such phrase may find some. I'd start by reading the overview.html and faq.html documents that come with it.
Fundamentally, the jcifs.smb.SmbFile, SmbFileInputStream and SmbFileOutputStream classes are meant as replacements for the java.io.File, FileInputStream and FileOutputStream classes. That means their respective APIs are very similar -if not identical- to those. If you read through the example codes that come with it you'll see how that works.
I think this is pretty straightforward if you look at the API:
The rest of your code basically remains the same.
Joined: Jul 03, 2010
Thanks a lot Rob for your help and suggestion.I tried using the snippet that you have suggested.However the code is not compiling as its giving errors like:-
What are the prerequisite for using these classes?Kindly help me to solve the problem at the earliest.
Joined: Jul 03, 2010
@Rob:-I figured out my mistake.I just included jcifs jar files and my project runs correctly.Thanks a lot for your help.However,just a little doubt do i need to share the destination folder to copy the required file?Is there no way in which i could transfer the file to the remote machine without having to share the destination folder?Its a security concern Kindly help.
You will need a share to put the file on; otherwise where are you going to put it? If you secure this share properly (i.e. nobody can read/write unless you specify they can) there should be no security issue. Others can see the share is there, but they can't access it.
If you also want to hide the share you can share it with a trailing $, for example "share$". This will hide it from explorer et all. I don't know if this trick also works with non-Windows clients, but from Windows 2000 until Windows 7 this really works. Just remember to use the proper name; you must also use the $ when accessing it.
Note that just hiding is not securing it. If anyone finds out it exists they can still enter the path manually. That's why you still need the proper security settings.