This commit is contained in:
Looly
2019-11-20 00:15:52 +08:00
parent eec404f875
commit 106ea5a759
12 changed files with 399 additions and 378 deletions

View File

@@ -133,13 +133,14 @@ public abstract class AbstractFtp implements Closeable {
}
/**
* 将本地文件上传到目标服务器目标文件名为destPath若destPath为目录则目标文件名将与srcFilePath文件名相同。覆盖模式
* 将本地文件上传到目标服务器目标文件名为destPath若destPath为目录则目标文件名将与file文件名相同。
* 覆盖模式
*
* @param srcFilePath 本地文件路径
* @param destFile 目标文件
* @param destPath 服务端路径,可以为{@code null} 或者相对路径或绝对路径
* @param file 需要上传的文件
* @return 是否成功
*/
public abstract boolean upload(String srcFilePath, File destFile);
public abstract boolean upload(String destPath, File file);
/**
* 下载文件

View File

@@ -364,14 +364,14 @@ public class Ftp extends AbstractFtp {
* 3. path为绝对路径则上传到此路径
* </pre>
*
* @param path 服务端路径,可以为{@code null} 或者相对路径或绝对路径
* @param destPath 服务端路径,可以为{@code null} 或者相对路径或绝对路径
* @param file 文件
* @return 是否上传成功
*/
@Override
public boolean upload(String path, File file) {
public boolean upload(String destPath, File file) {
Assert.notNull(file, "file to upload is null !");
return upload(path, file.getName(), file);
return upload(destPath, file.getName(), file);
}
/**

View File

@@ -238,9 +238,6 @@ public class JschUtil {
*/
public static int openAndBindPortToLocal(Connector sshConn, String remoteHost, int remotePort) throws JschRuntimeException {
final Session session = openSession(sshConn.getHost(), sshConn.getPort(), sshConn.getUser(), sshConn.getPassword());
if (session == null) {
throw new JschRuntimeException("Error to create SSH Session");
}
final int localPort = generateLocalPort();
bindPort(session, remoteHost, remotePort, localPort);
return localPort;
@@ -359,7 +356,7 @@ public class JschUtil {
if (null == charset) {
charset = CharsetUtil.CHARSET_UTF_8;
}
ChannelExec channel = (ChannelExec) openChannel(session, ChannelType.EXEC);
final ChannelExec channel = (ChannelExec) openChannel(session, ChannelType.EXEC);
channel.setCommand(StrUtil.bytes(cmd, charset));
channel.setInputStream(null);
channel.setErrStream(errStream);

View File

@@ -1,12 +1,9 @@
package cn.hutool.extra.ssh;
import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.List;
import java.util.Vector;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.lang.Filter;
import cn.hutool.core.util.StrUtil;
import cn.hutool.extra.ftp.AbstractFtp;
import com.jcraft.jsch.ChannelSftp;
import com.jcraft.jsch.ChannelSftp.LsEntry;
import com.jcraft.jsch.ChannelSftp.LsEntrySelector;
@@ -14,10 +11,11 @@ import com.jcraft.jsch.Session;
import com.jcraft.jsch.SftpException;
import com.jcraft.jsch.SftpProgressMonitor;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.lang.Filter;
import cn.hutool.core.util.StrUtil;
import cn.hutool.extra.ftp.AbstractFtp;
import java.io.File;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.List;
import java.util.Vector;
/**
* SFTP是Secure File Transfer Protocol的缩写安全文件传送协议。可以为传输文件提供一种安全的加密方法。<br>
@@ -336,8 +334,8 @@ public class Sftp extends AbstractFtp {
}
@Override
public boolean upload(String srcFilePath, File destFile) {
put(srcFilePath, FileUtil.getAbsolutePath(destFile));
public boolean upload(String destPath, File file) {
put(FileUtil.getAbsolutePath(file), destPath);
return true;
}