0

im getting the following error, when I want to execute my Java program:

Exception in thread "main" java.lang.NoSuchMethodError: org.apache.commons.net.ftp.FTPSClient.setCopyStreamListener(Lorg/apache/commons/net/io/CopyStreamListener;)V
    at PzFtpUpload.<init>(PzFtpUpload.java:77)
    at Javatest.<init>(Javatest.java:29)
    at Javatest.main(Javatest.java:602)

And here is my constructor, where I need to set the CopyStreamListener with an override.

public PzFtpUpload() {

    ftps = new FTPSClient("TLS"); // SSL/TLS ggf zu einem späteren zeitpunkt
    ftps.setCopyStreamListener(

        new CopyStreamAdapter() {

        @Override
        public void bytesTransferred(long totalBytesTransferred, int bytesTransferred, long streamSize) {

            File uploadfile = new File(path);

               try{
                    PrintWriter writer = new PrintWriter("C:\\Users\\lsp\\Desktop\\status.txt", "UTF-8");
                    writer.println((int)(totalBytesTransferred/uploadfile.length()) * 100);
                    writer.close();
                } catch (IOException e) {
                   System.out.println("Error writing status file.");
                }
        }

     });
}
  • Check your version of Apache Commons Net, this method exists since 3.0 : https://commons.apache.org/proper/commons-net/apidocs/org/apache/commons/net/ftp/FTPClient.html#setCopyStreamListener(org.apache.commons.net.io.CopyStreamListener) – Arnaud Apr 25 '17 at 13:53
  • Im working with 3.3 since the beginning of my developing. –  Apr 25 '17 at 13:54
  • Could you add the relevant part from `PzFtpUpload` ? – Arnaud Apr 25 '17 at 13:56
  • Looke above..... –  Apr 25 '17 at 13:59
  • Since the code compiles and the error occurs at runtime, you probably have an old version of Commons Net in the classpath when your application is running.Try to print the result of `FTPSClient.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath()` to see which jar it comes from. – Arnaud Apr 25 '17 at 14:01
  • I get the following: "/C:/pz/classpath/commons-net-3.3.jar" –  Apr 25 '17 at 14:16
  • Otherwise, I just need a method, that writes the percentage of an upload into a text file - all I found is just the method you can see above. If there is a more simple way (without override etc) please let me know. –  Apr 25 '17 at 14:41
  • nobody got a hint / solution for that ? –  Apr 26 '17 at 12:42

0 Answers0