- String fn = "SshJcraftWrapper.sftp";
- try {
- Session sftpSession = jsch.getSession(userName, hostName, 22);
- UserInfo ui = new MyUserInfo();
- sftpSession.setPassword(passWord);
- sftpSession.setUserInfo(ui);
- sftpSession.connect(30 * 1000);
- debugLog.printRTAriDebug(fn, "Opening up an sftp channel....");
- ChannelSftp sftp = (ChannelSftp) sftpSession.openChannel("sftp");
- debugLog.printRTAriDebug(fn, "Connecting....");
- sftp.connect();
- debugLog.printRTAriDebug(fn, "Sending " + sourcePath + " --> " + destDirectory);
- sftp.put(sourcePath, destDirectory, ChannelSftp.OVERWRITE);
- debugLog.printRTAriDebug(fn, "Sent successfully");
- sftpSession.disconnect();
- } catch (Exception e) {
- debugLog.printRTAriDebug(fn, "Caught an Exception, e=" + e);
- // dbLog.storeData("ErrorMsg= sftp threw an Exception. error is:"+e);
- throw new IOException(e.toString());
- }