Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- String SFTPHOST = "166.62.85.112";
- int SFTPPORT = 22;
- String SFTPUSER = "username";
- String SFTPPASS = "password";
- String SFTPWORKINGDIR = "c:/";
- Session session = null;
- Channel channel = null;
- ChannelSftp channelSftp = null;
- try{
- JSch jsch = new JSch();
- session = jsch.getSession(SFTPUSER,SFTPHOST,SFTPPORT);
- session.setPassword(SFTPPASS);
- java.util.Properties config = new java.util.Properties();
- config.put("StrictHostKeyChecking", "no");
- session.setConfig(config);
- session.connect();
- channel = session.openChannel("sftp");
- channel.connect();
- channelSftp = (ChannelSftp)channel;
- channelSftp.cd("c:/");
- 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