I am trying to write code in java to check if a directory exists or not on remote server. I have tried something mentioned on Check whether the path exists on server or not in Java.
ChannelSftp channelSftp = new ChannelSftp();
SftpATTRS attrs = null;
try {
String currentDirectory = channelSftp.pwd();
System.out.println(currentDirectory);
} catch (SftpException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
try {
attrs = channelSftp.stat("/x/web/STAGE2MA49/qatools/capturescripts_new");
} catch (Exception e) {
// TODO Auto-generated catch block
System.out.println(" not found");
}
But the above code did work out. Below is the error stack
at com.jcraft.jsch.ChannelSftp.getHome(ChannelSftp.java:2443)
at com.jcraft.jsch.ChannelSftp.getCwd(ChannelSftp.java:2452)
at com.jcraft.jsch.ChannelSftp.pwd(ChannelSftp.java:2429)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:215)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:142)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:336)
at org.testng.SuiteRunner.run(SuiteRunner.java:268)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1244)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1169)
at org.testng.TestNG.run(TestNG.java:1064)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:113)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:206)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:177)
Caused by: java.lang.NullPointerException
at com.jcraft.jsch.ChannelSftp.getHome(ChannelSftp.java:2435)
... 21 more