mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
fix code
This commit is contained in:
@@ -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);
|
||||
|
||||
/**
|
||||
* 下载文件
|
||||
|
@@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -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);
|
||||
|
@@ -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;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user