客户端日志上传
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
package com.sv.intergration;
|
||||
|
||||
import com.jcraft.jsch.*;
|
||||
import com.sv.netty.config.NettyConstant;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
public class LogService {
|
||||
|
||||
private static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
||||
|
||||
static Session session;
|
||||
|
||||
public void uploadLog(String password) throws JSchException, FileNotFoundException, SftpException {
|
||||
if (session == null){
|
||||
JSch jsch = new JSch();
|
||||
String serverIp = System.getProperty(NettyConstant.VENUE_SERVER_IP);
|
||||
session = jsch.getSession("root", serverIp, 22);
|
||||
session.setPassword(System.getProperty(NettyConstant.VENUE_CHECK_PWD));
|
||||
session.setConfig("StrictHostKeyChecking", "no");
|
||||
session.connect(3000);
|
||||
}
|
||||
ChannelSftp sftp = (ChannelSftp) session.openChannel("sftp");
|
||||
File file = new File("/home/venue/logs/common-default.log");
|
||||
if (file.exists()){
|
||||
sftp.put(new FileInputStream(file),"/home/uploadlog/" + System.getProperty(NettyConstant.VENUE_CLIENT_SN) + "-" + sdf.format(new Date()) + "-client.log");
|
||||
}
|
||||
if (sftp != null) {
|
||||
sftp.connect();
|
||||
sftp.disconnect();
|
||||
}
|
||||
if (session != null) {
|
||||
session.disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user