• Post Reply Bookmark Topic Watch Topic
  • New Topic

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

 
Baranenko Nikolay
Greenhorn
Posts: 16
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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.
 
Campbell Ritchie
Marshal
Posts: 52580
119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Question too difficult for “beginning”. Let's try our IO forum instead.
 
Paul Clapham
Sheriff
Posts: 21886
36
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • 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: 16
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
option resolve to the problem




sorce code here

 
Paul Clapham
Sheriff
Posts: 21886
36
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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: 52580
119
  • Mark post as helpful
  • send pies
  • 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.
 
Casper Chen
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • 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
  • 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")
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!