• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Piet Souris
  • Carey Brown
  • Stephan van Hulst
Bartenders:
  • Frits Walraven
  • fred rosenberger
  • salvin francis

Error inTransfering file to the remote system

 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Greenhorn
Posts: 6
Eclipse IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Sheriff
Posts: 22258
119
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
neha priya
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Rancher
Posts: 43024
76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
jCIFS comes with a wide variety of example codes and documentation.
 
neha priya
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Rancher
Posts: 43024
76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 22258
119
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@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
Posts: 22258
119
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
reply
    Bookmark Topic Watch Topic
  • New Topic