smbjcifs

How to move (not copy) a file with JCIFS?


I'm wondering how I can move a file from one folder to another on an SMB share, using JCIFS.

First, there is no move() method whatsoever.

Then, this approach:

SmbFile smbFromFile = new SmbFile("smb://...pool/from-here/the-file.pdf", auth);
SmbFile smbToFile = new SmbFile("smb://...pool/to-here/the-file.pdf", auth);
smbFromFile.renameTo(smbToFile);

throws an Exception, "The system cannot find the path specified."

Rename only works in the same path. Altering the parameters doesn't help.

Right now, I'm using

smbFromFile = new SmbFile("smb://...pool/from-here/the-file.pdf", auth);
smbToFile = new SmbFile("smb://...pool/to-here", auth);
smbFromFile.copyTo(smbToFile);
smbFromFile.delete();

This feels somehow wrong.

Unfortunately, in the docu I don't find anything about moving a file.

Does somebody have a bit more information? It should be a part of SMB, right (SMB_COM_MOVE)?


Solution

  • Turned out I was a muppet as I had messed up my configuration parameters.

    Both ways are working fine:

    Method 1:

    SmbFile smbFromFile = new SmbFile("smb://...pool/from-here/the-file.pdf", auth);
    SmbFile smbToFile = new SmbFile("smb://...pool/to-here/the-file.pdf", auth);
    smbFromFile.renameTo(smbToFile); 
    

    Method 2:

    smbFromFile = new SmbFile("smb://...pool/from-here/the-file.pdf", auth);
    smbToFile = new SmbFile("smb://...pool/to-here/the-file.pdf", auth);
    smbFromFile.copyTo(smbToFile);
    smbFromFile.delete();