I want to upload a file to the ftps server. The below code works for small files like 10KB. but I need to upload 5-10 MB files. and the error comes with the below error line. Can someone help me with this? Below code which I tried. Is there a better way to do this?
Error Line
boolean result = con.storeFile(FILE_NAME, multipartFile.getInputStream());
Code
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();
}
}
Error Message
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