1

Am try to get all files present in UNC path using apache commons-vfs2 library.

But am not find way to list files present in UNC path with valid credentials.And then do manipulations in all files.

I tried following code for access file present in UNC.

String domain="xxxxx";
String userName="xyz";
String password="aabbcc";
File f=new File("E:/destination");
String remoteFilePath="\\\\hostname\\foldername";
UserAuthenticator auth=new StaticUserAuthenticator(domain, userName, password);
FileSystemOptions opts=new FileSystemOptions();
DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator(opts, auth);
FileObject fo=VFS.getManager().resolveFile(remoteFilePath,opts);
FileObject destn=VFS.getManager().resolveFile(f.getAbsolutePath());
destn.copyFrom(fo,Selectors.SELECT_SELF);
destn.close();

Here i have given filename append with remoteFilePath it moves that file into my destination directory.

If i give only directory name in remoteFilePath it not worked.

Now i need to get all files present in "UNC Path" without give filename.After reading those files then do some changes inside files to be moved into destination directory.

Anyone suggest way to do it?

Mister X
  • 3,406
  • 3
  • 31
  • 72
  • cifs in apache vfs is in sandbox state. If the remote device is mounted you don't need any library. I suppose you refactor to use `java.io.File.listFiles()` to find the files inside the directory. BTW: I'm missing some sort of loop in your code. – blafasel Sep 06 '17 at 11:46
  • listFiles() not working when i access network drive with credentials.Tha'ts why am go to vfs – Mister X Sep 06 '17 at 11:51
  • You need to specify the method name used to Retter the smb provider, like smb://server/share - and also use forward slashes as VFS works on URL syntax. – eckes Nov 05 '20 at 22:02

0 Answers0