Windows搭建SFTP服务器

  https://www.cnblogs.com/wangjunguang/p/9453611.html

  注意点:

    1.以管理员权限运行FreeSSHd

    2.如果无法启动,应该是后台服务已经启动,需要在服务里面关掉

写一个SFTPClient工具类

package com.koukay.Controller.Controllers.util;
import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;
import com.jcraft.jsch.ChannelSftp;
import com.jcraft.jsch.SftpATTRS;
import com.jcraft.jsch.SftpException;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.util.concurrent.TimeUnit;

@Component
@Slf4j
public class SFTPClient {
private final static Logger log = LoggerFactory.getLogger(SFTPClient.class);
@Value("${sftp.directory}")
private String ftpPath;

private volatile boolean isConfig = false;

private ChannelSftpPool channelSftpPool;

@Value("${sftp.host}")
private String host ;// 服务器ip地址

@Value("${sftp.username}")
private String username ; //账号

@Value("${sftp.password}")
private String password ;//密码

@Value("${sftp.port}")
private int port ;// 端口号

private final Cache<Object, Object> cache = Caffeine.newBuilder()
.maximumSize(1000)
.expireAfterAccess(15, TimeUnit.MINUTES)
.build();

private void initSFTPConfig() {

log();

if (isConfig) {
return;
}

isConfig = true;

if (log.isDebugEnabled()) {
log.debug("加载SFTP配置:{}");
}

int ftpPort = this.port;
String ftpServer =this.host;
String ftpAccount = this.username;
String ftpPassword = this.password;

//如果没有配置路径则获取登录用户根目录
if (StringUtils.isEmpty(ftpPath)) {
ftpPath = ".";
}
ftpPath = ftpPath.replaceAll("\\\\", "/");

channelSftpPool = new ChannelSftpPool(new ChannelSftpPoolConfig(), new ChannelSftpPooledObjectFactory(false,
null, ftpServer, ftpAccount, ftpPassword, ftpPort));
}

private void log() {
if (channelSftpPool != null) {
log.info("getMaxTotal = {},getNumActive = {},getNumIdle = {},createCount = {},borrowedCount = {},destroyedCount = {}",
channelSftpPool.internalPool.getMaxTotal(),
channelSftpPool.internalPool.getNumActive(),
channelSftpPool.internalPool.getNumIdle(),
channelSftpPool.internalPool.getCreatedCount(),
channelSftpPool.internalPool.getBorrowedCount(),
channelSftpPool.internalPool.getDestroyedCount());
}
}

public void rebuild() {
isConfig = false;
if (channelSftpPool != null) {
channelSftpPool.close();
}
initSFTPConfig();
}

/**
* 创建SFTP连接
*
* @return ChannelSftp
* @throws Exception
*/
public ChannelSftp createSftp() {
initSFTPConfig();
return channelSftpPool.getResource();
}

/**
* 关闭连接
*
* @param sftp sftp
*/
public void disconnect(ChannelSftp sftp) {
if (sftp != null) {
channelSftpPool.returnResourceObject(sftp);
}
}

/**
* 上传文件
*
* @param fileName
* @param inputStream
* @return
* @throws Exception
*/
public boolean uploadFile(String fileName, InputStream inputStream) throws Exception {
initSFTPConfig();
ChannelSftp sftp = this.channelSftpPool.getResource();
createFolder(sftp);
try {
sftp.put(inputStream, getFileName(fileName), ChannelSftp.OVERWRITE);
return true;
} catch (Exception e) {
log.error("Upload file failure. TargetPath: {}", fileName, e);
throw new Exception("Upload File failure");
} finally {
if (sftp != null) this.disconnect(sftp);
}
}
/**
* 删除文件
*
* @param fileName
* @return
* @throws Exception
*/
public boolean deleteFile(String fileName) throws Exception {
initSFTPConfig();
ChannelSftp sftp = this.channelSftpPool.getResource();
try {
fileName = getFileName(fileName);
sftp.rm(fileName);
return true;
} catch (Exception e) {
log.error("Delete file failure. TargetPath: {}", fileName, e);
throw new Exception("Delete File failure");
} finally {
if (sftp != null) this.disconnect(sftp);
}
}

/**
* 下载文件
*
* @param fileName
* @return
* @throws Exception
*/
public void downloadFile(String fileName, HttpServletResponse response) throws Exception {
initSFTPConfig();
ChannelSftp sftp = this.channelSftpPool.getResource();
OutputStream outputStream = response.getOutputStream();
try {
fileName = getFileName(fileName);
log.info("sftp pwd = {},fileName = {}", sftp.pwd(), fileName);
byte[] bytes = (byte[]) cache.getIfPresent(fileName);
if (bytes == null) {
bytes = getFromSftp(fileName);
}
if (bytes != null) {
IOUtils.copy(new ByteArrayInputStream(bytes), outputStream);
} else {
log.info("sftp fileName = {} non-existent!!!", fileName);
}
} catch (Exception e) {
log.error("Download file failure. TargetPath: {}", fileName, e);
throw new Exception("Download File failure");
} finally {
if (sftp != null) this.disconnect(sftp);
}
}

public byte[] getFromSftp(String fileName) {
initSFTPConfig();
ChannelSftp sftp = this.channelSftpPool.getResource();
try (InputStream in = sftp.get(fileName)) {
ByteArrayOutputStream out = new ByteArrayOutputStream();
IOUtils.copy(in, out);
byte[] bytes = out.toByteArray();
return bytes;
} catch (SftpException | IOException e) {
log.error(e.getMessage(), e);
} finally {
if (sftp != null) this.disconnect(sftp);
}
return null;
}

/**
* 下载文件到特定目录
*
* @param fileName
* @return
* @throws Exception
*/
public void downloadFileToDir(String fileName, String dirPath) throws Exception {
initSFTPConfig();
ChannelSftp sftp = this.channelSftpPool.getResource();
File file = new File(dirPath+File.separator+fileName);
FileOutputStream fos = new FileOutputStream(file);
try {
fileName = getFileName(fileName);
log.info("sftp pwd = {},fileName = {}", sftp.pwd(), fileName);
sftp.get(fileName, fos);
fos.flush();
} catch (Exception e) {
log.error("Download file failure. TargetPath: {}", fileName, e);
throw new Exception("Download File failure");
} finally {
if (sftp != null) this.disconnect(sftp);
if (fos != null) {
fos.close();
}
}
}

public String getFileName(String fileName) {
if (ftpPath.endsWith("/")) {
fileName = ftpPath + fileName;
} else {
fileName = ftpPath + "/" + fileName;
}
return fileName;
}

/**
* 校验是否可以连接成功
*
* @return 是否成功
*/
public Boolean checkSftp() {
isConfig = false;
if (channelSftpPool != null) {
channelSftpPool.close();
}
initSFTPConfig();
ChannelSftp sftp = null;
try {
sftp = this.channelSftpPool.getResource();
sftp.cd(".");
} catch (Exception e) {
log.debug(e.getMessage());
return false;
} finally {
if (sftp != null) this.disconnect(sftp);
}
return true;
}

/**
* 判断文件是否存在,删除前判断
* @param fileName
* @return
*/
public boolean fileExist(String fileName) {
initSFTPConfig();
ChannelSftp sftp = null;
try {
sftp = this.channelSftpPool.getResource();
SftpATTRS attrs = sftp.lstat(getFileName(fileName));
return true;
}catch (SftpException e) {
if (e.id == ChannelSftp.SSH_FX_NO_SUCH_FILE) {
log.info("file {} not exist.", fileName);
}
}finally {
if (sftp != null) this.disconnect(sftp);
}
return false;
}

/**
* 判断文件夹是否存在,不存在则创建
* @param sftp
* @return
*/
public boolean createFolder(ChannelSftp sftp) {
boolean exist=true;
String[] splitDirs = ftpPath.split("/");
try {
//判断文件夹是否存在
sftp.stat(ftpPath);
} catch (SftpException e) {
//不存在的话逐级判断并创建
for (int i = 0; i < splitDirs.length; i++) {
SftpATTRS attr =null;
String splitDir = splitDirs[i];
if (i==0) {
try {
//进入根目录
sftp.cd("/");
} catch (SftpException sftpException) {
sftpException.printStackTrace();
}
}
if (StringUtils.isNotEmpty(splitDir)) {
try {
//判断每级文件夹是否存在
attr = sftp.stat(splitDir);
sftp.cd(splitDir);
} catch (SftpException sftpException) {
if (attr==null){
try {
log.info("文件夹不存在,正在创建:" + splitDir);
sftp.mkdir(splitDir);
log.info("完成创建子目录:" + splitDir);
exist= true;
sftp.cd(splitDir);
} catch (SftpException sftpException1) {
exist=false;
log.info("文件夹创建失败:" + sftpException1);
}
}
}
}
}
}
return exist;
}
}
package com.koukay.Controller.Controllers.util;

import com.jcraft.jsch.ChannelSftp;
import org.apache.commons.pool2.PooledObjectFactory;
import org.apache.commons.pool2.impl.GenericObjectPoolConfig; public class ChannelSftpPool extends Pool<ChannelSftp> { public ChannelSftpPool(GenericObjectPoolConfig<ChannelSftp> poolConfig, PooledObjectFactory<ChannelSftp> factory) {
super(poolConfig, factory);
} }
package com.koukay.Controller.Controllers.util;

import com.jcraft.jsch.ChannelSftp;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory; @Slf4j
public class ChannelSftpPoolConfig extends GenericObjectPoolConfig<ChannelSftp> {
private final static Logger log = LoggerFactory.getLogger(ChannelSftpPoolConfig.class);
public ChannelSftpPoolConfig() {
int maxTotal = str2Int(SpringBeanUtils.getProperty("koukay.sftp.maxTotal"), 10);
int maxWaitMillis = str2Int(SpringBeanUtils.getProperty("koukay.sftp.maxWaitMillis"), 10000);
setTestWhileIdle(true);
setMinEvictableIdleTimeMillis(60000);
setTimeBetweenEvictionRunsMillis(30000);
setNumTestsPerEvictionRun(-1);
setMaxWaitMillis(maxWaitMillis);
setMaxTotal(maxTotal);
} private int str2Int(String property, int defaultValue) {
if (StringUtils.isNotBlank(property)) {
try {
return Integer.parseInt(property);
} catch (NumberFormatException e) {
log.error("property sftp.maxTotal is error,import_limit = {}", property);
}
}
return defaultValue;
}
}
package com.koukay.Controller.Controllers.util;

import com.jcraft.jsch.Channel;
import com.jcraft.jsch.ChannelSftp;
import com.jcraft.jsch.JSch;
import com.jcraft.jsch.Session;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.pool2.PooledObject;
import org.apache.commons.pool2.PooledObjectFactory;
import org.apache.commons.pool2.impl.DefaultPooledObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory; @Slf4j
public class ChannelSftpPooledObjectFactory implements PooledObjectFactory<ChannelSftp> {
private final static Logger log = LoggerFactory.getLogger(ChannelSftpPooledObjectFactory.class);
private boolean publicKeyAuthentication; private String idRsaPath;
private String ftpServer;
private String ftpAccount;
private String ftpPassword;
private int ftpPort; public ChannelSftpPooledObjectFactory(boolean publicKeyAuthentication, String idRsaPath, String ftpServer,
String ftpAccount, String ftpPassword, int ftpPort) {
this.publicKeyAuthentication = publicKeyAuthentication;
this.idRsaPath = idRsaPath;
this.ftpServer = ftpServer;
this.ftpAccount = ftpAccount;
this.ftpPassword = ftpPassword;
this.ftpPort = ftpPort;
} @Override
public PooledObject<ChannelSftp> makeObject() throws Exception {
JSch jsch = new JSch();
if (publicKeyAuthentication) {
jsch.addIdentity(idRsaPath);
}
Session session = createSession(jsch, ftpServer, ftpAccount, ftpPort);
session.setPassword(ftpPassword);
session.setServerAliveInterval(60000);
session.connect();
Channel channel = session.openChannel("sftp");
channel.connect();
return new DefaultPooledObject<ChannelSftp>((ChannelSftp) channel);
} @Override
public void destroyObject(PooledObject<ChannelSftp> p) throws Exception {
log.info("destroyObject ChannelSftp!");
disconnect(p.getObject());
} @Override
public boolean validateObject(PooledObject<ChannelSftp> p) {
return true;
} @Override
public void activateObject(PooledObject<ChannelSftp> p) throws Exception {
p.getObject().getSession().sendKeepAliveMsg();
} @Override
public void passivateObject(PooledObject<ChannelSftp> p) throws Exception { } /**
* 创建session
*
* @param jsch
* @param host
* @param username
* @param port
* @return
* @throws Exception
*/
private Session createSession(JSch jsch, String host, String username, Integer port) throws Exception {
Session session; if (port <= 0) {
session = jsch.getSession(username, host);
} else {
session = jsch.getSession(username, host, port);
} if (session == null) {
throw new Exception(host + " session is null");
}
java.util.Properties config = new java.util.Properties();
config.put("StrictHostKeyChecking", "no");
session.setConfig(config);
return session;
} /**
* 关闭连接
*
* @param sftp
*/
public void disconnect(ChannelSftp sftp) {
try {
if (sftp != null) {
if (sftp.isConnected()) {
sftp.disconnect();
} else if (sftp.isClosed()) {
log.info("sftp is closed already");
}
if (sftp.getSession() != null) {
sftp.getSession().disconnect();
}
}
} catch (Exception e) {
log.error("", e);
}
}
}
package com.koukay.Controller.Controllers.util;

import lombok.extern.slf4j.Slf4j;
import org.apache.commons.pool2.PooledObjectFactory;
import org.apache.commons.pool2.impl.GenericObjectPool;
import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import java.io.Closeable;
import java.util.NoSuchElementException; @Slf4j
public abstract class Pool<T> implements Closeable {
private final static Logger log = LoggerFactory.getLogger(Pool.class);
protected GenericObjectPool<T> internalPool; /**
* Using this constructor means you have to set and initialize the internalPool yourself.
*/
public Pool() {
} public Pool(final GenericObjectPoolConfig<T> poolConfig, PooledObjectFactory<T> factory) {
initPool(poolConfig, factory);
} @Override
public void close() {
destroy();
} public boolean isClosed() {
return this.internalPool.isClosed();
} public void initPool(final GenericObjectPoolConfig<T> poolConfig, PooledObjectFactory<T> factory) { if (this.internalPool != null) {
try {
closeInternalPool();
} catch (Exception e) {
log.error(e.getMessage(), e);
}
} this.internalPool = new GenericObjectPool<T>(factory, poolConfig);
} public T getResource() {
try {
return internalPool.borrowObject();
} catch (NoSuchElementException nse) {
if (null == nse.getCause()) { // The exception was caused by an exhausted pool
throw new IllegalStateException(
"Could not get a resource since the pool is exhausted", nse);
}
// Otherwise, the exception was caused by the implemented activateObject() or ValidateObject()
throw new IllegalStateException("Could not get a resource from the pool", nse);
} catch (Exception e) {
throw new IllegalStateException("Could not get a resource from the pool", e);
}
} protected void returnResourceObject(final T resource) {
if (resource == null) {
return;
}
try {
internalPool.returnObject(resource);
} catch (Exception e) {
throw new IllegalStateException("Could not return the resource to the pool", e);
}
} protected void returnBrokenResource(final T resource) {
if (resource != null) {
returnBrokenResourceObject(resource);
}
} protected void returnResource(final T resource) {
if (resource != null) {
returnResourceObject(resource);
}
} public void destroy() {
closeInternalPool();
} protected void returnBrokenResourceObject(final T resource) {
try {
internalPool.invalidateObject(resource);
} catch (Exception e) {
throw new IllegalStateException("Could not return the broken resource to the pool", e);
}
} protected void closeInternalPool() {
try {
internalPool.close();
} catch (Exception e) {
throw new IllegalStateException("Could not destroy the pool", e);
}
} /**
* Returns the number of instances currently borrowed from this pool.
*
* @return The number of instances currently borrowed from this pool, -1 if
* the pool is inactive.
*/
public int getNumActive() {
if (poolInactive()) {
return -1;
} return this.internalPool.getNumActive();
} /**
* Returns the number of instances currently idle in this pool.
*
* @return The number of instances currently idle in this pool, -1 if the
* pool is inactive.
*/
public int getNumIdle() {
if (poolInactive()) {
return -1;
} return this.internalPool.getNumIdle();
} /**
* Returns an estimate of the number of threads currently blocked waiting for
* a resource from this pool.
*
* @return The number of threads waiting, -1 if the pool is inactive.
*/
public int getNumWaiters() {
if (poolInactive()) {
return -1;
} return this.internalPool.getNumWaiters();
} /**
* Returns the mean waiting time spent by threads to obtain a resource from
* this pool.
*
* @return The mean waiting time, in milliseconds, -1 if the pool is
* inactive.
*/
public long getMeanBorrowWaitTimeMillis() {
if (poolInactive()) {
return -1;
} return this.internalPool.getMeanBorrowWaitTimeMillis();
} /**
* Returns the maximum waiting time spent by threads to obtain a resource
* from this pool.
*
* @return The maximum waiting time, in milliseconds, -1 if the pool is
* inactive.
*/
public long getMaxBorrowWaitTimeMillis() {
if (poolInactive()) {
return -1;
} return this.internalPool.getMaxBorrowWaitTimeMillis();
} private boolean poolInactive() {
return this.internalPool == null || this.internalPool.isClosed();
} public void addObjects(int count) {
try {
for (int i = 0; i < count; i++) {
this.internalPool.addObject();
}
} catch (Exception e) {
throw new IllegalStateException("Error trying to add idle objects", e);
}
}
}
package com.koukay.Controller.Controllers.util;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component; @Component
public class SpringBeanUtils implements ApplicationContextAware { public static ApplicationContext applicationContext; @Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
this.applicationContext = applicationContext;
} public static String getProperty(String key) {
if (applicationContext != null) {
return applicationContext.getEnvironment().getProperty(key);
}
return null;
}
}

依赖如下

<dependency>
<groupId>com.jcraft</groupId>
<artifactId>jsch</artifactId>
<version>0.1.54</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.4</version>
</dependency>
<dependency>
<groupId>com.github.ben-manes.caffeine</groupId>
<artifactId>caffeine</artifactId>
<version>2.8.5</version>
</dependency>

上面的可以引入项目直接用,以下写个测试代码,

package util;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.Properties;
import java.util.Vector; import com.jcraft.jsch.*; /**
*
* @author patronli
*
*/
public class FtpService {
ChannelSftp sftp = null;
Session sshSession =null;
String host = "192.168.8.159";// 服务器ip地址
String username = "root";
String password = "123456";
int port = 22;// 端口号 /**
* 连接sftp服务器
*
* @param host
* 主机
* @param port
* 端口
* @param username
* 用户名
* @param password
* 密码
* @return
*/
public ChannelSftp connect(String host, int port, String username,
String password) {
System.out.println("开始连接sftp"); try {
JSch jsch = new JSch();
jsch.getSession(username, host, port);
sshSession = jsch.getSession(username, host, port);
System.out.println("Session created.");
sshSession.setPassword(password);
Properties sshConfig = new Properties();
sshConfig.put("StrictHostKeyChecking", "no");
sshSession.setConfig(sshConfig);
sshSession.connect();
System.out.println("Session connected.");
System.out.println("Opening Channel.");
Channel channel = sshSession.openChannel("sftp");
channel.connect();
sftp = (ChannelSftp) channel;
System.out.println("Connected to " + host + ".");
System.out.println("连接sftp成功..");
} catch (Exception e) {
System.out.println("连接失败");
e.printStackTrace();
}
return sftp;
} /**
* 上传文件
*
* @param directory
* 上传的目录
* @param uploadFile
* 要上传的文件
* @param sftp
*/
public void upload(String directory, String uploadFile, ChannelSftp sftp) {
System.out.println("进入方法,开始读取文件");
try {
sftp.cd(directory);
File file = new File(uploadFile);
System.out.println("开始上传报表文件" + file.getName());
sftp.put(new FileInputStream(file), file.getName());
System.out.println("上传报表文件" + file.getName() + "完毕");
System.out.println("上传报表文件成功");
} catch (Exception e) {
System.out.println("上传报表文件失败");
e.printStackTrace();
}
} /**
* 下载文件
*
* @param directory
* 下载目录
* @param sftp
* 下载的文件
* @param path
* 存在本地的路径
*/
public void download(String directory, String downloadFile, ChannelSftp sftp, String path) {// sftp路径,链接,保存的路径+文件名
try {
sftp.cd(directory);
File file = new File(path);
sftp.get(downloadFile, new FileOutputStream(file));
System.out.println("下载成功:" + path);
} catch (Exception e) {
System.out.println("下载文件出现异常:::");
e.printStackTrace();
}
} /**
* 删除文件
*
* @param directory
* 要删除文件所在目录
* @param deleteFile
* 要删除的文件
* @param sftp
*/
public void delete(String directory, String deleteFile, ChannelSftp sftp) {
try {
sftp.cd(directory);
sftp.rm(deleteFile);
} catch (Exception e) {
e.printStackTrace();
}
} /**
* 列出目录下的文件
*
* @param directory
* 要列出的目录
* @param sftp
* @return
* @throws SftpException
*/
public Vector listFiles(String directory, ChannelSftp sftp)
throws SftpException {
return sftp.ls(directory);
} public void deal(int judge) {
String directory = "";
//改成自己要上传的文件名
String fileName = "msdia80.dll";
String localUrl = "D:\\";// 文件下载到本地的地址,虚拟机上的格式/home/fy_flg/reportFile/
String path = localUrl + fileName;// 路径+文件名
ChannelSftp sftp = connect(host, port, username, password);
try {
if (judge == 1) {// 表示上传
directory = "/upload/";// sftp操作文件的目录
upload(directory, path, sftp);// 上传--sftp目录,要上传文件的地址
}else if (judge == 2){ //下载
directory = "/upload/";// sftp操作文件的目录
path="C:\\Users\\lx\\Desktop\\"+fileName;
fileName=directory+fileName;
download(directory,fileName, sftp,path);// 下载文件--sftp目录,要下载的文件名字,下载到的地方,
}else if (judge == 3){
directory = "/upload/";// sftp操作文件的目录
delete(directory, fileName, sftp);// 删除--sftp目录,要上传文件的地址
} else if (judge == 4){
directory = "/upload/";
try {
Vector vector = listFiles(directory, sftp);
for (Object o : vector) {
System.out.println(o.toString());
}
} catch (SftpException e) {
e.printStackTrace();
}
}
}finally {
disconnect();
}
}
/**
* 关闭连接
*/
public void disconnect() {
if (this.sftp != null) {
if (this.sftp.isConnected()) {
this.sftp.disconnect();
this.sftp = null;
System.out.println("sftp 连接已关闭!");
}
}
if (this.sshSession != null) {
if (this.sshSession.isConnected()) {
this.sshSession.disconnect();
this.sshSession = null;
System.out.println("sshSession 连接已关闭!");
}
}
}
public static void main(String[] args) {
FtpService sf = new FtpService();
sf.deal(4);
} }

Java上传文件至SFTP服务器的更多相关文章

  1. java 上传文件到 ftp 服务器

    1.  java 上传文件到 ftp 服务器 package com.taotao.common.utils; import java.io.File; import java.io.FileInpu ...

  2. Java 上传文件到 SFTP 抛异常 java.lang.NoClassDefFoundError: Could not initialize class sun.security.ec.SunEC 的解决办法

    最近从 Op 那里报来一个问题,说是SFTP上传文件不成功.拿到的 Exception 如下: Caused by: java.lang.NoClassDefFoundError: Could not ...

  3. Java上传文件FTP服务器代码

    1. 在实际的应用重,通常是通过程序来进行文件的上传. 2. 实现java上传文件到ftp服务器中 新建maven项目 添加依赖 <dependency> <groupId>c ...

  4. SpringBoot 上传文件到linux服务器 异常java.io.FileNotFoundException: /tmp/tomcat.50898……解决方案

    SpringBoot 上传文件到linux服务器报错java.io.FileNotFoundException: /tmp/tomcat.50898-- 报错原因: 解决方法 java.io.IOEx ...

  5. SpringBoot上传文件到本服务器 目录与jar包同级问题

    目录 前言 原因 实现 不要忘记 最后的封装 Follow up   前言 看标题好像很简单的样子,但是针对使用jar包发布SpringBoot项目就不一样了.当你使用tomcat发布项目的时候,上传 ...

  6. C# 上传文件至远程服务器

    C# 上传文件至远程服务器(适用于桌面程序及web程序) 2009-12-30 19:21:28|  分类: C#|举报|字号 订阅     最近几天在玩桌面程序,在这里跟大家共享下如何将本地文件上传 ...

  7. ASP.NET上传文件到远程服务器(HttpWebRequest)

    /// <summary> /// 文件上传至远程服务器 /// </summary> /// <param name="url">远程服务地址 ...

  8. asp.net 服务器 上传文件到 FTP服务器

    private string ftpServerIP = "服务器ip";//服务器ip private string ftpUserID = "ftp的用户名" ...

  9. .Net 上传文件到ftp服务器和下载文件

    突然发现又很久没有写博客了,想起哎呦,还是写一篇博客记录一下吧,虽然自己还是那个渣渣猿. 最近在做上传文件的功能,上传到ftp文件服务器有利于管理上传文件. 前面的博客有写到layui如何上传文件,然 ...

随机推荐

  1. coolshell-初见

    首页:https://coolshell.cn/tag/programmer 我是怎么招聘程序员的 https://coolshell.cn/articles/1870.html 程序员需要具备的基本 ...

  2. 网卡激活-up(dhcp方式获得ip)

    一次修复记录 采样: [root@fp-web-124 network-scripts]# cat /etc/redhat-release CentOS Linux release 7.2.1511 ...

  3. 演示默认学习用户scott,默认密码是tiger

    默认学习用户scott,默认密码是tiger oracle@prd:/home/oracle$sqlplus /nolog SQL> conn scott/tiger ERROR: ORA-28 ...

  4. mosquitto使用与常用配置

    为了方便演示,我这里就用windows环境下安装的mosquitto进行操作,操作方式和linux系统下是一样的. 一.windows安装mosquitto 下载mosquitto mosquitto ...

  5. SLF4J (The Simple Logging Facade for Java)使用记录

    SLF4J (The Simple Logging Facade for Java)使用记录 官网 http://www.slf4j.org/ 参考资料 官方文档 什么是 SLF4J? 官网: The ...

  6. vue 跨域配置代理 get/post 请求

    1.第一步要有 axios 插件 : npm i axios 首先要在自己的项目手动添加一个文件 vue.config.js 个人理解的为 这是axios 封装的跨域文件. 2.vue.config. ...

  7. 国产化之银河麒麟.netcore3.1访问https服务的两个问题

    背景 某个项目需要实现基础软件全部国产化,其中操作系统指定银河麒麟,数据库使用达梦V8,CPU平台的范围包括x64.龙芯.飞腾.鲲鹏等. 考虑到这些基础产品对.NETCore的支持,最终选择了3.1版 ...

  8. java序列回显学习

    java反序列化回显 在很多不出网的情况下,一种是写webshell(内存嘛),另一种就是回显,本文先学习回显,回显的主要方式有一下几种. defineClass RMI绑定实例 URLClassLo ...

  9. oauth协议原理

    oauth协议关系图(如获取微信用户信息): oauth一般授权步骤:

  10. [还不会搭建博客吗?]centos7系统部署hexo博客新手入门-进阶,看这一篇就够了

    @ 目录 *本文说明 请大家务必查看 前言 首先介绍一下主角:Hexo 什么是 Hexo? 环境准备 详细版 入门:搭建步骤 安装git: 安装node: 安装Hexo: 进阶:hexo基本操作 发布 ...