|
@@ -5,13 +5,17 @@ import com.nokia.common.ssh.entity.SSHServer;
|
|
|
import com.nokia.common.ssh.entity.UserInfoImpl;
|
|
|
import com.nokia.common.ssh.exception.SSHUtilException;
|
|
|
import com.nokia.common.ssh.exception.ScpAckErrorException;
|
|
|
+import com.xxl.job.core.context.XxlJobHelper;
|
|
|
import lombok.Getter;
|
|
|
import lombok.Setter;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
|
import java.io.*;
|
|
|
import java.nio.file.NoSuchFileException;
|
|
|
-import java.util.*;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Properties;
|
|
|
+import java.util.Vector;
|
|
|
|
|
|
/**
|
|
|
* 使用jsch库实现的ssh的工具类
|
|
@@ -143,12 +147,12 @@ public class SSHUtil {
|
|
|
inputStream = channel.getInputStream();
|
|
|
channel.connect();
|
|
|
if (checkAck(inputStream) != 0) {
|
|
|
- log.error("scpTo 执行失败");
|
|
|
+ XxlJobHelper.handleFail("scpTo 执行失败");
|
|
|
return false;
|
|
|
}
|
|
|
File sourceFile = new File(sourceFilePath);
|
|
|
if (sourceFile.isDirectory()) {
|
|
|
- log.error("sourceFilePath 必须是文件");
|
|
|
+ XxlJobHelper.handleFail("sourceFilePath 必须是文件");
|
|
|
return false;
|
|
|
}
|
|
|
long fileSize = sourceFile.length();
|
|
@@ -156,7 +160,7 @@ public class SSHUtil {
|
|
|
outputStream.write(command.getBytes());
|
|
|
outputStream.flush();
|
|
|
if (checkAck(inputStream) != 0) {
|
|
|
- log.error("scpTo 执行失败");
|
|
|
+ XxlJobHelper.handleFail("scpTo 执行失败");
|
|
|
return false;
|
|
|
}
|
|
|
fileInputStream = new FileInputStream(sourceFile);
|
|
@@ -182,7 +186,7 @@ public class SSHUtil {
|
|
|
*/
|
|
|
public boolean scpFrom(String sourceFilePath, String targetPath) throws JSchException, IOException, SSHUtilException {
|
|
|
try {
|
|
|
- log.debug(sourceFilePath);
|
|
|
+ XxlJobHelper.log(sourceFilePath);
|
|
|
session = getConnectSession();
|
|
|
// scp内置了两个参数 -t 和 -f ,这两个参数是隐藏的,不会被用户显式提供,
|
|
|
// 两个scp进程之间传输数据时,远端机器上的scp进程被本地scp进程启动起来时提供上去。
|
|
@@ -233,7 +237,7 @@ public class SSHUtil {
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
- log.debug("filesize={}, file={}", filesize, file);
|
|
|
+ XxlJobHelper.log("filesize={}, file={}", filesize, file);
|
|
|
// 发送 '0'
|
|
|
buf[0] = 0;
|
|
|
outputStream.write(buf, 0, 1);
|
|
@@ -241,7 +245,7 @@ public class SSHUtil {
|
|
|
// 如果目标是目录,则需要加上文件名
|
|
|
File target = new File(targetPath);
|
|
|
if (target.isDirectory()) {
|
|
|
- log.debug("{} 是目录,需要添加文件名", target.getAbsolutePath());
|
|
|
+ XxlJobHelper.log("{} 是目录,需要添加文件名", target.getAbsolutePath());
|
|
|
target = new File(targetPath + File.separator + file);
|
|
|
}
|
|
|
|
|
@@ -270,7 +274,7 @@ public class SSHUtil {
|
|
|
buf[0] = 0;
|
|
|
outputStream.write(buf, 0, 1);
|
|
|
outputStream.flush();
|
|
|
- log.debug("scp from {}@{}:{}{} to {} 完成", targetServer.getUser(), targetServer.getHost(), targetServer.getPort(), sourceFilePath, target.getAbsolutePath());
|
|
|
+ XxlJobHelper.log("scp from {}@{}:{}{} to {} 完成", targetServer.getUser(), targetServer.getHost(), targetServer.getPort(), sourceFilePath, target.getAbsolutePath());
|
|
|
return true;
|
|
|
} finally {
|
|
|
disconnect();
|
|
@@ -287,7 +291,7 @@ public class SSHUtil {
|
|
|
properties.put("StrictHostKeyChecking", "no");
|
|
|
session.setConfig(properties);
|
|
|
session.connect();
|
|
|
- log.debug("已连接到{}@{}:{}", targetServer.getUser(), targetServer.getHost(), targetServer.getPort());
|
|
|
+ XxlJobHelper.log("已连接到{}@{}:{}", targetServer.getUser(), targetServer.getHost(), targetServer.getPort());
|
|
|
return session;
|
|
|
}
|
|
|
|
|
@@ -341,7 +345,7 @@ public class SSHUtil {
|
|
|
c = in.read();
|
|
|
sb.append((char) c);
|
|
|
} while (c != '\n');
|
|
|
- log.debug("checkAck发现错误消息: ack={}-msg={}", b, sb);
|
|
|
+ XxlJobHelper.log("checkAck发现错误消息: ack={}-msg={}", b, sb);
|
|
|
if (b == 1 && sb.toString().endsWith("No such file or directory")) {
|
|
|
throw new NoSuchFileException(sb.toString());
|
|
|
} else {
|