Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- String host = "166.62.85.112";
- int port = 22;
- String user = "username";
- String password = "password";
- String workingDirectory = "c:/";
- Session session = null;
- Channel channel = null;
- ChannelSftp channelSftp = null;
- try {
- JSch jsch = new JSch();
- session = jsch.getSession(user, host, port);
- session.setPassword(password);
- Properties config = new Properties();
- config.put("StrictHostKeyChecking", "no");
- session.setConfig(config);
- session.connect();
- channel = session.openChannel("sftp");
- channel.connect();
- channelSftp = (ChannelSftp) channel;
- channelSftp.cd(workingDirectory);
- File f = new File("D:/test.xlsx");
- channelSftp.put(new FileInputStream(f), f.getName());
- } catch (Exception ex) {
- ex.printStackTrace();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement