/**
* 获取连接
* @param ip 跳转机host
* @param userName 跳转机用户名
* @param pwd 跳转机密码
* @param port 跳转机端口
* @return ChannelSftp 返回值
* @throws JSchException 连接异常
*/
public static ChannelSftp connect(String ip, String userName, String pwd, int port) throws JSchException
{
if (port <= 0)
{
port = PORT;
}
Session sshSession = null;
JSch jsch = new JSch();
sshSession = jsch.getSession(userName, ip, port);
sshSession.setPassword(pwd);
Properties sshConfig = new Properties();
sshConfig.put("StrictHostKeyChecking", "no");
sshConfig.put("PreferredAuthentications",
"password,keyboard-interactive");
sshSession.setConfig(sshConfig);
sshSession.connect(TMOUT);//可设置超时时间
//此处开始为端口映射到本地的部分
sshSession.setPortForwardingL(本地端口, 目标节点地址, 22);
//完成上诉映射之后,即可通过本地端口连接了
Session session = jsch.getSession("目标服务用户名", "127.0.0.1",本地端口);
Properties remoteCfg = new Properties();
remoteCfg.put("StrictHostKeyChecking", "no");
remoteCfg.put("PreferredAuthentications",
"password,keyboard-interactive");
session.setConfig(remoteCfg);
session.setPassword("目标服务密码");
session.connect();
//后续如何可自行改变,网上运用很多
Channel channel = (Channel) session.openChannel("sftp");//创建sftp通信通道
channel.connect();
ChannelSftp sftp = (ChannelSftp) channel;
return sftp;
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有