Reputation: 10947
WinSCP based same connection using account name, passphrase and private key for connection. But trying from code am getting this exception continuously.
Code:
try
{
session.connect();
System.out.println("session is alive:" + session.isConnected());
channel = session.openChannel("sftp");
channel.connect();
channelSftp = (ChannelSftp) channel;
channelSftp.connect();
channelSftp.chmod(777, depDir);
}
catch (Exception e1)
{
e1.printStackTrace();
System.out.println("Manual Exception in updateDepositedFilePermission:" + CommonUtil.getExceptionString(e1));
}
Output:
session is alive:true
Manual Exception in updateDepositedFilePermission:com.jcraft.jsch.JSchException: failed to send sftp request
at com.jcraft.jsch.RequestSftp.request(Unknown Source)
at com.jcraft.jsch.ChannelSftp.start(Unknown Source)
at com.jcraft.jsch.Channel.connect(Unknown Source)
at com.app.sftp.CheckFTP.main(CheckFTP.java:730)
session is alive:true
com.jcraft.jsch.JSchException: failed to send sftp request
at com.jcraft.jsch.RequestSftp.request(Unknown Source)
at com.jcraft.jsch.ChannelSftp.start(Unknown Source)
at com.jcraft.jsch.Channel.connect(Unknown Source)
at com.app.sftp.CheckFTP.main(CheckFTP.java:730)
Upvotes: 2
Views: 3580
Reputation: 202088
Not sure it's the main problem, but you are calling Channel.connect()
twice.
First here:
channel.connect();
And again here:
channelSftp.connect();
Remove the second call.
Upvotes: 2