aspose file tools
The moose likes Java in General and the fly likes Error inTransfering file to the remote system Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "Error inTransfering file to the remote system" Watch "Error inTransfering file to the remote system" New topic
Author

Error inTransfering file to the remote system

neha priya
Ranch Hand

Joined: Jul 03, 2010
Posts: 62
Hi,

I need to tranfer a file from my local system to the remote machine.I have used the following sample code:-

However on execution of the above code,i am getting the following exception:-


Kindly help as how do i resolve the exception.If possible please suggest a better to transfer the file to the remote system.

Regards
Oguzhan Acargil
Greenhorn

Joined: Apr 16, 2010
Posts: 6

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?
neha priya
Ranch Hand

Joined: Jul 03, 2010
Posts: 62
Thanks for the reply.The remote machine is on a different network and the credentials are :-
username:-user
Password:-password

how do i specify these credentials through the java code.

Please help.

Regards.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19216

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.


SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
neha priya
Ranch Hand

Joined: Jul 03, 2010
Posts: 62
Thanks Rob for the quick reply.Could you please explain with a snippet as how do i use JCIFS and SmbFile to achieve remote file transfer?How do i provide the credentials there?

Kindly reply.
Regards.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 35247
    
    7
jCIFS comes with a wide variety of example codes and documentation.


Android appsImageJ pluginsJava web charts
neha priya
Ranch Hand

Joined: Jul 03, 2010
Posts: 62
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.

Regards.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 35247
    
    7
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.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19216

I think this is pretty straightforward if you look at the API:
The rest of your code basically remains the same.
neha priya
Ranch Hand

Joined: Jul 03, 2010
Posts: 62
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.

Regards.
neha priya
Ranch Hand

Joined: Jul 03, 2010
Posts: 62
@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.

Regards.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19216

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.
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Error inTransfering file to the remote system
 
Similar Threads
using byte array to copy contents of one file to another
how to copy files at runtime
copy file from local host to remote host
Corrupt GZIP trailer
current path