I'm trying to upload excel file using SFTP to linux machine from my local windows PC.
Here is my code:
private void uploadToSftp() {
try
{
ChannelSftp sftpClient = null;
Channel channel = null;
JSch jsch = new JSch();
Session session = jsch.getSession("username", "host", 22);
session.setPassword("password");
Properties config = new Properties();
config.put("StrictHostKeyChecking","no");
session.setConfig(config);
session.connect();
channel = session.openChannel("sftp");
channel.connect();
sftpClient = (ChannelSftp) channel;
sftpClient.cd("/var/www/folder");
File localFile = new File("C:\\Workspace\\upload-file\\test.xlsx");
sftpClient.put(localFile.getAbsolutePath(),localFile.getName());
sftpClient.disconnect();
channel.disconnect();
session.disconnect();
} catch (JSchException e) {
e.printStackTrace();
} catch (SftpException e) {
e.printStackTrace();
}
}
but every time i run this application i get error:
3: Permission denied
at com.jcraft.jsch.ChannelSftp.throwStatusError(ChannelSftp.java:2873)
at com.jcraft.jsch.ChannelSftp._put(ChannelSftp.java:594)
at com.jcraft.jsch.ChannelSftp.put(ChannelSftp.java:475)
at com.jcraft.jsch.ChannelSftp.put(ChannelSftp.java:365)
Doesn anyone know what could be problem and how can i solve this?