Random error while trying to read directory
Status: Alpha
Brought to you by:
ymnk
Hello Dear support:
I have a code that we use to access a server and read some files, but unfortunately we are facing a random problem in this line: channel.lcd(localDir); that occurs very rarely.
The code is below and the description of the error as well:
Error
2018-01-16 02:39:51,808 C [TestScheduler_Worker-48] ERROR - Exception occurred:
3: Permission denied.
Code
Line:
channel.lcd(localDir);
Method:
private ChannelSftp getSftpChannel() throws Exception { if (sftpSession == null) { JSch jsch = new JSch(); sftpSession = jsch.getSession(user, host, port); java.util.Properties config = new java.util.Properties(); config.put("StrictHostKeyChecking", "no"); sftpSession.setTimeout(timeout); sftpSession.setConfig(config); // not ssl connection, will connect with username/password if (!ftpOverSSLFlag) { sftpSession.setConfig("PreferredAuthentications", "password,keyboard-interactive"); sftpSession.setPassword(password); }else { // if private key will connect with key file jsch.addIdentity(privateKeyPath); } //Modify the way to connect to the sftp channel if(noKeyboardInteractive){ sftpSession.setConfig("PreferredAuthentications", "password"); sftpSession.setPassword(password); } sftpSession.connect(); } ChannelSftp channel = (ChannelSftp) sftpSession.openChannel("sftp"); channel.connect(); channel.cd(remoteDir); **channel.lcd(localDir);** return channel; }
Any help would be highly appreciated.