1

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

Roberto Caboni
  • 7,252
  • 10
  • 25
  • 39
  • why don't you try using some ssh libraries like JSch, SSHJ? Any limitations? – Kumar V May 21 '20 at 02:01
  • I don't know much about ftps servers. I just wanna upload a file to ftps server. what you meant by limitations? this error comes with, storeFile line. – Buddhi Hasanka May 21 '20 at 05:20

1 Answers1

0

Have you tried with changing max size in webapps/manager/WEB-INF/web.xml? I think this might help you Max limit of multi part file

Nirodha
  • 16
  • Yes, I already did. # Multipart Content Configs spring.servlet.multipart.enabled=true spring.servlet.multipart.file-size-threshold=5KB spring.servlet.multipart.max-file-size=500MB spring.servlet.multipart.max-request-size=515MB spring.messages.fallback-to-system-locale=false thanks. – Buddhi Hasanka May 26 '20 at 08:19