我想将文件上传到ftps服务器。以下代码适用于10KB之类的小文件。但我需要上传5-10 MB的文件。错误在错误行下方。有人可以帮我弄这个吗?下面我尝试过的代码。有更好的方法吗?
boolean result = con.storeFile(FILE_NAME, multipartFile.getInputStream());
public void createDeviceVersion(MultipartFile multipartFile) {
String FTP_ADDRESS = backendConfigRepo.findByConfigKey(KeyConstant.FTP_ADDRESS).getConfigValue();
int FTP_PORT = Integer.parseInt(backendConfigRepo.findByConfigKey(KeyConstant.FTP_PORT).getConfigValue());
String USER = backendConfigRepo.findByConfigKey(KeyConstant.FTP_USER).getConfigValue();
String PASSWORD = backendConfigRepo.findByConfigKey(KeyConstant.FTP_PASSWORD).getConfigValue();
String FILE_NAME = backendConfigRepo.findByConfigKey(KeyConstant.MCASH_VERSION_FILE_NAME).getConfigValue();
FTPSClient con = null;
try {
con = new FTPSClient(true);
con.connect(FTP_ADDRESS, FTP_PORT);
if (con.login(USER, PASSWORD)) {
con.enterLocalPassiveMode();
con.setFileType(FTP.BINARY_FILE_TYPE);
boolean result = con.storeFile(FILE_NAME, multipartFile.getInputStream());
System.out.println(result);
con.logout();
con.disconnect();
}
} catch (Exception e) {
e.printStackTrace();
}
}
org.apache.commons.net.io.CopyStreamException: IOException caught while copying.
at org.apache.commons.net.io.Util.copyStream(Util.java:136)
at org.apache.commons.net.ftp.FTPClient._storeFile(FTPClient.java:675)
at org.apache.commons.net.ftp.FTPClient.__storeFile(FTPClient.java:639)
at org.apache.commons.net.ftp.FTPClient.storeFile(FTPClient.java:2160)
....
Caused by: java.net.SocketException: Connection reset by peer: socket write error
....
您是否尝试过更改webapps/manager/WEB-INF/web.xml
中的最大尺寸?我认为这可能对您有帮助enter link description here