Win a copy of React Cookbook: Recipes for Mastering the React Framework this week in the HTML Pages with CSS and JavaScript forum!
  • 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
  • Paul Clapham
  • Rob Spoor
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Holloway
  • Piet Souris
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Frits Walraven
  • Himai Minh

Java JCIFS how right to copy file from Samba to Windows local?

 
Greenhorn
Posts: 18
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hellow.

I try to create java application which can to copy files from Unix Samba to Windows folder. For resolve task I found JCIFS lib.

I try to write code




try this one




But have error


BUT if try for example create file on samba. Operation completed OK.




Please help to resolve problem.
 
Marshal
Posts: 73733
332
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Question too difficult for “beginning”. Let's try our IO forum instead.
 
Marshal
Posts: 26750
81
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You could try "smb://192.168.10.1/data" (which matches what you did in your working code) rather than "smb:////192.168.10.1//data" (which is in your non-working code).

However your second example strongly suggests that "smb://192.168.10.1/data" is a folder, in which case trying to copy from it as if it were a file isn't going to work.

Whether either of those two issues would produce the stack trace you posted, I don't know. I haven't used jCIFS (at least in terms of developing code using it) for about a decade now.
 
Baranenko Nikolay
Greenhorn
Posts: 18
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
option resolve to the problem




sorce code here

 
Paul Clapham
Marshal
Posts: 26750
81
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for posting the working code, Noner. Just one comment: if you are using Java 7 or later (and surely you must be) then you could simplify it by using the Files.copy(InputStream, Path) method from the java.nio.file package. You would replace the code which copies the data from SMB to Windows by a single line of code calling the static Files.copy method.

Also if you look at the API documentation for Files.copy, the detailed description of the method contains an example which shows how to use the try-with-resources feature. That would make your finally-clause (with all of the annoying null tests) unnecessary as well, so your code would look much simpler.
 
Campbell Ritchie
Marshal
Posts: 73733
332
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Clapham wrote:. . . if you are using Java 7 or later . . .

I thought the link given seemed to contain old‑fashioned code.
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


you wanna copy file through samba protocol to local disk.
the path of local file should be presented by "smb://localhost/C$/Temp/IN/" (windows) , and it works.
 
Casper Chen
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Casper Chen wrote:

you wanna copy file through samba protocol to local disk.
the path of local file should be presented by "smb://localhost/C$/Temp/IN/" (windows) , and it works.



Note.
auth should be local authentication. e.g. NtlmPasswordAuthentication( null, "localhost_account", "account_password")
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic