Description
FTPClient.storeFile() is incredibly slow. I have two example files, one FB (4MB) and one in ravel VB (94K) format. Under 3.1 both files transfer in less than a second (FB:328ms, VB:112ms). Under 3.2 the VB transfer takes 30,000ms, and the FB transfer takes too long to find out (> 15 minutes).
I have checked the FB file on the mainframe after cancelling the transfer and it is always partly there. But the length varies, suggesting that it hasn't hit the same error each time.
I have built two jar files, one with 3.1 and the other with 3.2. These jars are available. The code is as follows:
public class FTPTransfer { public static void transfer (String name, FTPClient ftp, File file) throws IOException { FileInputStream fis = new FileInputStream (file); long start = System.currentTimeMillis (); if (ftp.storeFile (name, fis)) System.out.print ("File transferred"); else System.out.print ("Transfer failed"); System.out.printf (" in %d ms%n", (System.currentTimeMillis () - start)); fis.close (); } public static void main (String[] args) { File file1 = null; File file2 = null; if (System.getProperty ("os.name").toLowerCase ().startsWith ("mac")) { file1 = new File ("/Users/Denis/comtest/DENIS-018.SRC"); // ravel file format file2 = new File ("/Users/Denis/comtest/MOLONYD.NCD"); // FB252 format } else { file1 = new File ("D:/comtest/DENIS-018.SRC"); // ravel file format file2 = new File ("D:/comtest/MOLONYD.NCD"); // FB252 format } FTPClient ftp = new FTPClient (); ftp.addProtocolCommandListener (new PrintCommandListener (new PrintWriter (System.out), true)); try { ftp.connect ("server"); int reply = ftp.getReplyCode (); if (!FTPReply.isPositiveCompletion (reply)) { ftp.disconnect (); System.err.println ("FTP server refused connection."); System.exit (1); } ftp.login ("user", "pw"); FTPFile[] files = ftp.listFiles (); System.out.printf ("%nListing contains %d files%n%n", files.length); ftp.setFileType (FTP.BINARY_FILE_TYPE); ftp.setFileStructure (FTP.RECORD_STRUCTURE); transfer ("TEST.VB", ftp, file1); ftp.setFileStructure (FTP.FILE_STRUCTURE); transfer ("TEST.FB", ftp, file2); ftp.logout (); } catch (IOException e) { e.printStackTrace (); } finally { if (ftp.isConnected ()) { try { ftp.disconnect (); } catch (IOException ioe) { } } } } }