0

How do you move a file from a local non-SMB folder to a SMB location in the server?

Below code doesn't work, but it's something like this what I am after. I am able to authenticate the smb location.

String sourceFile="target/abc.xml";
String smbDestinationFile="sharePath/abc/smblocation/xyz.xml";
SmbFile sTargetFile = performAuthenticationAndChecks(destinationFile, domain, domainUsername,
    domainPassword);
Files.move(Paths.get(sourceFile), (Path) sTargetFile);

I get this error:

java.lang.ClassCastException: jcifs.smb1.smb1.SmbFile cannot be cast to java.nio.file.Path
Oasis001
  • 79
  • 2
  • 17
  • 1
    "doesn't work" Please explain (e.g., show exception) as an update to your post. – Jeff Holt Feb 22 '22 at 15:22
  • @JeffHolt updated the question with exception – Oasis001 Feb 22 '22 at 15:23
  • `Paths.get(sTargetFile.getCanonicalPath())` might work instead of `(Path) sTargetFile`. – Jeff Holt Feb 22 '22 at 15:27
  • You may indeed have a samba problem but your immediate problem is not at all related to samba. It is merely a data type problem. The title of the question is not correct. – Jeff Holt Feb 22 '22 at 15:29
  • I don't think its a samba problem as I am able to auth and drop files at the SMB location without any issues. When I tried using getCanonicalPath() I get something like this:- java.nio.file.InvalidPathException: Illegal char <:> at index 4: smb1://sharePath/abc/smblocation/xyz.xml. Please notice '1' that appeared in the exception after smb. The actual path is something like this - smb://sharePath/abc/smblocation/xyz.xml. – Oasis001 Feb 22 '22 at 15:37
  • I meant Java-Samba problem, not samba problem. That is, after fixing the data type problem, you find something else wrong. – Jeff Holt Feb 22 '22 at 15:40
  • Seen [this](https://stackoverflow.com/questions/36339504/convert-smbfile-to-java-io-file)? – Jeff Holt Feb 22 '22 at 23:53

1 Answers1

0

You may be using an outdated library. Look for maintained alternatives such as JFileServer or jNQ.