|
@@ -147,11 +147,13 @@ 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;
|
|
|
}
|
|
@@ -160,6 +162,7 @@ public class SSHUtil {
|
|
|
outputStream.write(command.getBytes());
|
|
|
outputStream.flush();
|
|
|
if (checkAck(inputStream) != 0) {
|
|
|
+ log.error("scpTo 执行失败");
|
|
|
XxlJobHelper.handleFail("scpTo 执行失败");
|
|
|
return false;
|
|
|
}
|
|
@@ -186,6 +189,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 ,这两个参数是隐藏的,不会被用户显式提供,
|
|
@@ -237,6 +241,7 @@ public class SSHUtil {
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
+ log.debug("filesize={}, file={}", filesize, file);
|
|
|
XxlJobHelper.log("filesize={}, file={}", filesize, file);
|
|
|
// 发送 '0'
|
|
|
buf[0] = 0;
|
|
@@ -245,6 +250,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);
|
|
|
}
|
|
@@ -274,6 +280,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 {
|
|
@@ -291,6 +298,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;
|
|
|
}
|
|
@@ -345,6 +353,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());
|