Advertisement
anzure

FTP client file size increases

Apr 16th, 2016
27
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.90 KB | None | 0 0
  1.                                 FTPClient ftp = new FTPClient();
  2.                                 FileInputStream fis = null;
  3.                                 String hash = Utils.getCRC32(file);
  4.  
  5.                                 ftp.connect("ip");
  6.  
  7.                                 ftp.setFileTransferMode(FTP.BINARY_FILE_TYPE);
  8.                                 ftp.setFileType(FTP.BINARY_FILE_TYPE);
  9.                                 ftp.enterLocalPassiveMode();
  10.  
  11.                                 ftp.login("username", "password");
  12.  
  13.                                 fis = new FileInputStream(file);
  14.  
  15.                                 int endIndex = file.getName().lastIndexOf(".");
  16.                                 if (endIndex != -1){
  17.                                     String fName = file.getName().substring(0, endIndex);
  18.                                     String ext = file.getName().substring(endIndex, file.getName().length());
  19.                                     String fileName = fName + "_" + hash + ext;
  20.                                     Printer.log("Uploading " + fileName + "...");
  21.                                     ftp.storeFile(fileName, fis);
  22.                                     Printer.log("Successfully uploaded " + fileName + "!");
  23.                                 }
  24.  
  25.                                 ftp.logout();
  26.                                 ftp.disconnect();
  27.                                 fis.close();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement