0

I have develop a program for copy file from local-pc to remote pc (windows). When i mapped a drive it is working fine. But when not mapped or not logged in remote pc file is not coping. Given following exception:

java.io.IOException: The user name or password is incorrect
     at java.io.WinNTFileSystem.canonicalize0(Native Method)
     at java.io.Win32FileSystem.canonicalize(Win32FileSystem.java:414)
     at java.io.File.getCanonicalPath(File.java:618)
     at org.apache.commons.io.FileUtils.copyFile(FileUtils.java:1079)
     at org.apache.commons.io.FileUtils.copyFile(FileUtils.java:1038)

My code is below: For store user/pass in cmdkey

Runtime.getRuntime().exec("cmdkey /generic:"+ip+" /user:"+userName+" /pass:"+password );

For copy code:

import org.apache.commons.io.FileUtils;

FileUtils.copyFile(src, dest);

Please help me to fix the issue.

azro
  • 53,056
  • 7
  • 34
  • 70
learner
  • 1
  • 1
  • Possible duplicate of [xcopy with credentials on remote machine](https://stackoverflow.com/questions/14578175/xcopy-with-credentials-on-remote-machine) It looks like you have to map remote first – xxxvodnikxxx Apr 19 '18 at 08:56
  • 1
    Thanks it is working for me. – learner Apr 19 '18 at 09:08

1 Answers1

0
try {
      Runtime.getRuntime().exec("net use \"\\\\"+ip+"\" "+pass+" /user:"+user);
      System.out.println("Connected");

      Runtime.getRuntime().exec("net use \"\\\\"+ip+"\" /delete");
      System.out.println("Disconnected");
 } catch (IOException e) {
      e.printStackTrace();
 }
learner
  • 1
  • 1