use of com.jcraft.jsch.JSchException in project bamboobsc by billchen198318.
the class SFtpClientUtils method getRemoteFileList.
@SuppressWarnings("unchecked")
public static Vector<LsEntry> getRemoteFileList(String user, String password, String addr, int port, String cwd) throws JSchException, SftpException, Exception {
Session session = getSession(user, password, addr, port);
Vector<LsEntry> lsVec = null;
Channel channel = session.openChannel("sftp");
channel.connect();
ChannelSftp sftpChannel = (ChannelSftp) channel;
try {
//sftpChannel.lpwd()
lsVec = (Vector<LsEntry>) sftpChannel.ls(cwd);
} catch (Exception e) {
e.printStackTrace();
throw e;
} finally {
sftpChannel.exit();
channel.disconnect();
session.disconnect();
}
return lsVec;
}
use of com.jcraft.jsch.JSchException in project Lucee by lucee.
the class SFTPClientImpl method connect.
@Override
public void connect() throws SocketException, IOException {
try {
session = jsch.getSession(username, host.getHostAddress(), port);
java.util.Properties config = new java.util.Properties();
config.put("StrictHostKeyChecking", "no");
session.setConfig(config);
UserInfo ui = new UserInfoImpl(password, null);
session.setUserInfo(ui);
if (timeout > 0)
session.setTimeout(timeout);
session.connect();
Channel channel = session.openChannel("sftp");
channel.connect();
channelSftp = (ChannelSftp) channel;
// check fingerprint
if (!StringUtil.isEmpty(fingerprint)) {
if (!fingerprint.equalsIgnoreCase(fingerprint())) {
disconnect();
throw new IOException("given fingerprint is not a match.");
}
}
handleSucess();
} catch (JSchException e) {
handleFail(e, stopOnError);
}
}
use of com.jcraft.jsch.JSchException in project n2a by frothga.
the class Connection method receive.
public static Result receive(String remote, File dst) throws JSchException {
connect();
Result result = new Result();
FileOutputStream fos = null;
OutputStream out = null;
Channel channel = null;
try {
// exec 'scp -f rfile' remotely
String command = "scp -f '" + remote + "'";
channel = session.openChannel("exec");
((ChannelExec) channel).setCommand(command);
// get I/O streams for remote scp
out = channel.getOutputStream();
InputStream in = channel.getInputStream();
channel.connect();
byte[] buf = new byte[1024];
// send '\0'
buf[0] = 0;
out.write(buf, 0, 1);
out.flush();
while (true) {
int c = checkAck(in);
if (c != 'C') {
break;
}
// read '0644 '
in.read(buf, 0, 5);
long filesize = 0L;
while (true) {
if (in.read(buf, 0, 1) < 0) {
// error
break;
}
if (buf[0] == ' ') {
break;
}
filesize = filesize * 10L + (buf[0] - '0');
}
String file = null;
for (int i = 0; ; i++) {
in.read(buf, i, 1);
if (buf[i] == (byte) 0x0a) {
file = new String(buf, 0, i);
break;
}
}
// System.out.println("filesize="+filesize+", file="+file);
// send '\0'
buf[0] = 0;
out.write(buf, 0, 1);
out.flush();
// read a content of lfile
File outputFile;
if (dst.isDirectory()) {
outputFile = new File(dst, file);
} else {
outputFile = dst;
}
fos = new FileOutputStream(outputFile);
int foo;
while (true) {
if (buf.length < filesize) {
foo = buf.length;
} else {
foo = (int) filesize;
}
foo = in.read(buf, 0, foo);
if (foo < 0) {
// error
break;
}
fos.write(buf, 0, foo);
filesize -= foo;
if (filesize == 0L) {
break;
}
}
if (checkAck(in) != 0) {
System.exit(0);
}
// send '\0'
buf[0] = 0;
out.write(buf, 0, 1);
out.flush();
}
} catch (Exception e) {
result.error = true;
} finally {
if (fos != null) {
try {
fos.close();
} catch (Exception e) {
}
}
if (out != null) {
try {
out.close();
} catch (Exception e) {
}
}
if (channel != null) {
try {
channel.disconnect();
} catch (Exception e) {
}
}
}
return result;
}
use of com.jcraft.jsch.JSchException in project tigervnc by TigerVNC.
the class GSSContextKrb5 method create.
public void create(String user, String host) throws JSchException {
try {
// RFC 1964
Oid krb5 = new Oid("1.2.840.113554.1.2.2");
// Kerberos Principal Name Form
Oid principalName = new Oid("1.2.840.113554.1.2.2.1");
GSSManager mgr = GSSManager.getInstance();
GSSCredential crd = null;
/*
try{
GSSName _user=mgr.createName(user, principalName);
crd=mgr.createCredential(_user,
GSSCredential.DEFAULT_LIFETIME,
krb5,
GSSCredential.INITIATE_ONLY);
}
catch(GSSException crdex){
}
*/
String cname = host;
try {
cname = InetAddress.getByName(cname).getCanonicalHostName();
} catch (UnknownHostException e) {
}
GSSName _host = mgr.createName("host/" + cname, principalName);
context = mgr.createContext(_host, krb5, crd, GSSContext.DEFAULT_LIFETIME);
// RFC4462 3.4. GSS-API Session
//
// When calling GSS_Init_sec_context(), the client MUST set
// integ_req_flag to "true" to request that per-message integrity
// protection be supported for this context. In addition,
// deleg_req_flag MAY be set to "true" to request access delegation, if
// requested by the user.
//
// Since the user authentication process by its nature authenticates
// only the client, the setting of mutual_req_flag is not needed for
// this process. This flag SHOULD be set to "false".
// TODO: OpenSSH's sshd does accepts 'false' for mutual_req_flag
// context.requestMutualAuth(false);
context.requestMutualAuth(true);
context.requestConf(true);
// for MIC
context.requestInteg(true);
context.requestCredDeleg(true);
context.requestAnonymity(false);
return;
} catch (GSSException ex) {
throw new JSchException(ex.toString());
}
}
use of com.jcraft.jsch.JSchException in project linuxtools by eclipse.
the class ScpExec method init.
@Override
protected IStatus init() {
try {
channel = LinuxtoolsProcessFactory.execRemote(cmd, System.out, System.err, remoteOptions.userName, remoteOptions.hostName, remoteOptions.password, remoteOptions.port, envVars);
errorGobbler = new StreamGobbler(channel.getExtInputStream());
inputGobbler = new StreamGobbler(channel.getInputStream());
transferListeners();
return Status.OK_STATUS;
} catch (final JSchException | IOException e) {
return new Status(IStatus.ERROR, ConsoleLogPlugin.PLUGIN_ID, Messages.ScpExec_FileTransferFailed, e);
}
}
Aggregations