Hi Martin

The ScheduledExecutorService is used in my project and is part of the JDK/JRE since version 7. This class is probably not in apache commons net ftp, i dont know how you got that information? Guess a misunderstanding.

I read the documentation. I set the timeout of the ftp client to 20 seconds which should be long enough. Also, i see when it jumps inside my threads and executes them, and here is the problem. The socket is closed, which should _not_ be closed. But i dont know what is causing this wierd behaviour.

The project is open source. If you would like to take a look at it, i can send you the project url by private mail.

Regards

Oli


Am 29.08.2016 um 21:22 schrieb Martin Gainty:
having difficulty locating ScheduledExecutorService in 
commons-nethttps://commons.apache.org/proper/commons-net/javadocs/api-3.5/index.htmlwhich
 version commons-net are you implementing?

concerning ScheduledExecutorService running scheduleAtFixedRate or 
scheduleWithFixed methods there is a initial delay
built in so you maybe experiencing time-out after the initial connect during 
that initial delay
since we havent see the code you may want to look at ScheduledExecutorService  
examples 
herehttps://docs.oracle.com/javase/7/docs/api/java/util/concurrent/ScheduledExecutorService.html
Martin
Subject: Re: NPE in getRemoteAdress
To: [email protected]
From: [email protected]
Date: Mon, 29 Aug 2016 19:28:56 +0200

My download method looks like this:

private void downloadDirectory(FTPClient client, String sourceDir,
String destDir,
                                     ScheduledExecutorService
scheduledExecutorService) throws IOException {

          final FTPFile[] ftpFiles = client.listFiles(sourceDir);
          for (final FTPFile ftpFile : ftpFiles) {

              //skip . and ..
              if (ftpFile.isDirectory() && (ftpFile.getName().equals(".")
|| ftpFile.getName().equals(".."))) {
                  continue;
              }

              if (ftpFile.isDirectory()) {
                  downloadDirectory(client, sourceDir +
ftpFile.getName(), destDir + "/" + ftpFile.getName(),
scheduledExecutorService);
              } else {
//                scheduledExecutorService.submit(new
DownloadRunnable(destDir, ftpFile, sourceDir, client));
                  FileOutputStream fos = new
FileOutputStream(ftpFile.getName());
                  client.retrieveFile(sourceDir + ftpFile.getName(), fos );
                  fos.flush();
                  fos.close();
              }
          }
      }

When i run it like this, it works and it downloads the files. But when i
use the scheduledExecuterService, it fails.
So i replaced the 2 lines with my download method (where it uses the
inputstream) to see what happens:

   } else {
//                scheduledExecutorService.submit(new
DownloadRunnable(destDir, ftpFile, sourceDir, client));
                  new File(destDir).mkdirs();
                  final File outFile = new File(destDir, ftpFile.getName());
                  final FileOutputStream fos = new FileOutputStream(outFile);
                  final InputStream inputStream =
client.retrieveFileStream(sourceDir + ftpFile.getName());

                  byte[] buffer = new byte[8096];
                  int len = -1;
                  try {
                      len = inputStream.read(buffer, 0, buffer.length);
                  } catch (Exception ex) {
                      ex.printStackTrace();
                  }
                  while (len != -1) {
                      fos.write(buffer, 0, len);
                      len = inputStream.read(buffer);
                      if (Thread.interrupted()) {
                          throw new InterruptedException();
                      }
                  }
                  client.completePendingCommand();
//                informListenersWeFinishedOneFile(sourceDir +
ftpFile.getName(), bytesWritten);
                  fos.flush();
                  fos.close();
              }
          }

That works too?!

I will go deeper into that at weekend and check whats going on, but at
the moment i really dont understand it. Maybe some kind of concurrency
problem with FTPClient?


Am 29.08.2016 um 01:40 schrieb Martin Gainty:
possible timeout waiting for FTP to reply
examples.ftp.FTPClientExample says to increase FTP reply timeout with -w 
parameter
   if (args[base].equals("-w")) {                controlKeepAliveReplyTimeout = 
Integer.parseInt(args[++base]);            }
or with FTPClient:ftpClient.setControlKeepAliveReplyTimeout(2000); //2 sec 
reply timeout
?
Martin
______________________________________________



Date: Sun, 28 Aug 2016 20:06:46 +0200
From: [email protected]
To: [email protected]
CC: [email protected]
Subject: Re: NPE in getRemoteAdress

Hello,

I am not sure about your NPE, but this code here ignores the result of
the read call. It cannot deal with short reads:

   Am Sun, 28 Aug 2016
15:50:36 +0200 schrieb Oliver Zemann <[email protected]>:
byte b[] =new byte[4096];
while (inputStream.read(b) != -1) {
    fos.write(b);
    bytesWritten += b.length;
Gruss
Bernd

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

                                        

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

                                        


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to