RE: NPE in getRemoteAdress
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: e...@zusammenkunft.net > To: user@commons.apache.org > CC: oliver.zem...@gmail.com > 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: > > byte b[] =new byte[4096]; > > while (inputStream.read(b) != -1) { > > fos.write(b); > > bytesWritten += b.length; > > > Gruss > Bernd > > - > To unsubscribe, e-mail: user-unsubscr...@commons.apache.org > For additional commands, e-mail: user-h...@commons.apache.org >
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: > byte b[] =new byte[4096]; > while (inputStream.read(b) != -1) { > fos.write(b); > bytesWritten += b.length; Gruss Bernd - To unsubscribe, e-mail: user-unsubscr...@commons.apache.org For additional commands, e-mail: user-h...@commons.apache.org
Re: NPE in getRemoteAdress
ConnectionInfo is a JAXB Bean. I just have seen that thunderbird messed up some lines during copy/paste The connectionInfo is fully initialized, here is a short part of it: public class ConnectionInfo { @XmlElement(name = "Name") private String name; @XmlElement(name = "Host") private String host; @XmlElement(name = "Port") private int port; @XmlElement(name = "Username") private String username; @XmlElement(name = "Password") ... The connection to the FTP Server works. The FTP Client is logged in, CWD works, its just the transfer where i have problems. Am 28.08.2016 um 16:55 schrieb Martin Gainty: where is connectionInfo initialised? -M To: user@commons.apache.org From: oliver.zem...@gmail.com Subject: NPE in getRemoteAdress Date: Sun, 28 Aug 2016 15:50:36 +0200 Hi i am trying to get some files from a FTP Server. When i use retrieveFile(), it works, but i would like to add some listeners to it (how many bytes got transfered etc.) so i used retrieveFileStream(). Now i get some exceptions and no files are downloaded. This is the part of the code: @Override public void run() { try { 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 b[] =new byte[4096];//todo: would be nice to have such stuff in the appl conf so users can config it long bytesWritten =0; while (inputStream.read(b) != -1) { fos.write(b); bytesWritten += b.length; informDetailListeners(sourceDir +ftpFile.getName(), bytesWritten); bytesTransferedTotal += b.length; informListeners(bytesTransferedTotal); } client.completePendingCommand(); informListenersWeFinishedOneFile(sourceDir +ftpFile.getName(), bytesWritten); fos.flush(); fos.close(); System.out.println(client.getReplyString()); }catch (Exception ex) { System.out.println(client.getReplyString()); ex.printStackTrace(); } } The NullpointerException occurs in retrieveFileStream() - when i step into it i will get to FTPClient.java where it says: final boolean isInet6Address =getRemoteAddress()instanceof Inet6Address; getRemoteAddress() has this:return _socket_.getInetAddress(); When i try to debug into this, it just jumps into my catch block with a NullPointerException. When i add this method as watch, it says socket not connected - but it must be connected ?! The initialisation of the ftp Client is here: private void downloadTo(String destinationDir)throws IOException { //first, create the destination directory so we can write into that final File file =new File(destinationDir +"/" +sfdlFile.getDescription()); file.mkdirs(); //set up the connection and go to the directory we want final ConnectionInfo connectionInfo =sfdlFile.getConnectionInfo(); final String sourceDir =sfdlFile.getRemoteSourceDir(); final FTPClient client =new FTPClient(); client.connect(connectionInfo.getHost(), connectionInfo.getPort()); System.out.println(client.getReplyString()); client.enterLocalPassiveMode(); System.out.println(client.getReplyString()); client.login(connectionInfo.getUsername(), connectionInfo.getPassword()); System.out.println(client.getReplyString()); client.setFileType(FTP.BINARY_FILE_TYPE); System.out.println(client.getReplyString()); client.changeWorkingDirectory(sourceDir); System.out.println(client.getReplyString()); //now retrieve all files, recursive final ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(sfdlFile.getMaxThreads()); downloadDirectory(client, sourceDir, destinationDir +"/" +sfdlFile.getDescription(), scheduledExecutorService); client.disconnect(); System.out.println(client.getReplyString()); //inform our downloader we finished } The FTP Client is connected, the login worked, i get a lot of output from the Server which seems to be fine. Can someone tell me whats wrong with that code? Is there something i did not read in handling recursive downloads of (bigger) files ? The output in my intellij: 220 > 230 User logged in, proceed. 200 Type set to I. 250 Directory changed to /somedirectory null null java.lang.NullPointerException at org.apache.commons.net.SocketClient.getRemoteAddress(SocketClient.java:672) at org.apache.commons.net.ftp.FTPClient._openDataConnection_(FTPClient.java:819) at org.apache.commons.net.ftp.FTPClient._retrieveFileStream(FTPClient.java:1984) at org.apache.commons.net.ftp.FTPClient.retrieveFileStream(FTPClient.java:1971) at
RE: NPE in getRemoteAdress
where is connectionInfo initialised? -M > To: user@commons.apache.org > From: oliver.zem...@gmail.com > Subject: NPE in getRemoteAdress > Date: Sun, 28 Aug 2016 15:50:36 +0200 > > Hi > > i am trying to get some files from a FTP Server. When i use > retrieveFile(), it works, but i would like to add some listeners to it > (how many bytes got transfered etc.) so i used retrieveFileStream(). > Now i get some exceptions and no files are downloaded. > > This is the part of the code: > > @Override public void run() { > > try { > 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 b[] =new byte[4096];//todo: would be nice to have such stuff in > the appl conf so users can > config it long bytesWritten =0; > while (inputStream.read(b) != -1) { > fos.write(b); > bytesWritten += b.length; > informDetailListeners(sourceDir +ftpFile.getName(), > bytesWritten); > bytesTransferedTotal += b.length; > informListeners(bytesTransferedTotal); > } > client.completePendingCommand(); > informListenersWeFinishedOneFile(sourceDir +ftpFile.getName(), > bytesWritten); > fos.flush(); > fos.close(); > System.out.println(client.getReplyString()); > }catch (Exception ex) { > System.out.println(client.getReplyString()); > ex.printStackTrace(); > } > } > > The NullpointerException occurs in retrieveFileStream() - when i step > into it i will get to FTPClient.java where it says: > > final boolean isInet6Address =getRemoteAddress()instanceof Inet6Address; > > getRemoteAddress() has this:return _socket_.getInetAddress(); > When i try to debug into this, it just jumps into my catch block with a > NullPointerException. > When i add this method as watch, it says socket not connected - but it must > be connected ?! > > The initialisation of the ftp Client is here: > private void downloadTo(String destinationDir)throws IOException { > > //first, create the destination directory so we can write into that > final File file =new File(destinationDir +"/" +sfdlFile.getDescription()); > file.mkdirs(); > > //set up the connection and go to the directory we want final > ConnectionInfo connectionInfo =sfdlFile.getConnectionInfo(); > final String sourceDir =sfdlFile.getRemoteSourceDir(); > > final FTPClient client =new FTPClient(); > > client.connect(connectionInfo.getHost(), connectionInfo.getPort()); > System.out.println(client.getReplyString()); > client.enterLocalPassiveMode(); > System.out.println(client.getReplyString()); > client.login(connectionInfo.getUsername(), connectionInfo.getPassword()); > System.out.println(client.getReplyString()); > client.setFileType(FTP.BINARY_FILE_TYPE); > System.out.println(client.getReplyString()); > client.changeWorkingDirectory(sourceDir); > System.out.println(client.getReplyString()); > > //now retrieve all files, recursive final ScheduledExecutorService > scheduledExecutorService = > Executors.newScheduledThreadPool(sfdlFile.getMaxThreads()); > downloadDirectory(client, sourceDir, destinationDir +"/" > +sfdlFile.getDescription(), scheduledExecutorService); > > client.disconnect(); > System.out.println(client.getReplyString()); > //inform our downloader we finished } > > The FTP Client is connected, the login worked, i get a lot of output from the > Server which seems to be fine. > Can someone tell me whats wrong with that code? Is there something i did not > read in handling recursive downloads of (bigger) files ? > > The output in my intellij: > 220 > > > 230 User logged in, proceed. > > 200 Type set to I. > > 250 Directory changed to /somedirectory > > null > null > java.lang.NullPointerException > at > org.apache.commons.net.SocketClient.getRemoteAddress(SocketClient.java:672) > at > org.apache.commons.net.ftp.FTPClient._openDataConnection_(FTPClient.java:819) > at > org.apache.commons.net.ftp.FTPClient._retrieveFileStream(FTPClient.java:1984) > at > org.apache.commons.net.ftp.FTPClient.retrieveFileStream(FTPClient.java:1971) > at > de.trustserv.jsfdl.app.sfdl.SFDLFileDownloader$DownloadRunnable.run(SFDLFileDownloader.java:145) > at > java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) > at java.util.concurrent.FutureTask.run(FutureTask.java:266) > at > java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180) > at >
NPE in getRemoteAdress
Hi i am trying to get some files from a FTP Server. When i use retrieveFile(), it works, but i would like to add some listeners to it (how many bytes got transfered etc.) so i used retrieveFileStream(). Now i get some exceptions and no files are downloaded. This is the part of the code: @Override public void run() { try { 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 b[] =new byte[4096];//todo: would be nice to have such stuff in the appl conf so users can config it long bytesWritten =0; while (inputStream.read(b) != -1) { fos.write(b); bytesWritten += b.length; informDetailListeners(sourceDir +ftpFile.getName(), bytesWritten); bytesTransferedTotal += b.length; informListeners(bytesTransferedTotal); } client.completePendingCommand(); informListenersWeFinishedOneFile(sourceDir +ftpFile.getName(), bytesWritten); fos.flush(); fos.close(); System.out.println(client.getReplyString()); }catch (Exception ex) { System.out.println(client.getReplyString()); ex.printStackTrace(); } } The NullpointerException occurs in retrieveFileStream() - when i step into it i will get to FTPClient.java where it says: final boolean isInet6Address =getRemoteAddress()instanceof Inet6Address; getRemoteAddress() has this:return _socket_.getInetAddress(); When i try to debug into this, it just jumps into my catch block with a NullPointerException. When i add this method as watch, it says socket not connected - but it must be connected ?! The initialisation of the ftp Client is here: private void downloadTo(String destinationDir)throws IOException { //first, create the destination directory so we can write into that final File file =new File(destinationDir +"/" +sfdlFile.getDescription()); file.mkdirs(); //set up the connection and go to the directory we want final ConnectionInfo connectionInfo =sfdlFile.getConnectionInfo(); final String sourceDir =sfdlFile.getRemoteSourceDir(); final FTPClient client =new FTPClient(); client.connect(connectionInfo.getHost(), connectionInfo.getPort()); System.out.println(client.getReplyString()); client.enterLocalPassiveMode(); System.out.println(client.getReplyString()); client.login(connectionInfo.getUsername(), connectionInfo.getPassword()); System.out.println(client.getReplyString()); client.setFileType(FTP.BINARY_FILE_TYPE); System.out.println(client.getReplyString()); client.changeWorkingDirectory(sourceDir); System.out.println(client.getReplyString()); //now retrieve all files, recursive final ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(sfdlFile.getMaxThreads()); downloadDirectory(client, sourceDir, destinationDir +"/" +sfdlFile.getDescription(), scheduledExecutorService); client.disconnect(); System.out.println(client.getReplyString()); //inform our downloader we finished } The FTP Client is connected, the login worked, i get a lot of output from the Server which seems to be fine. Can someone tell me whats wrong with that code? Is there something i did not read in handling recursive downloads of (bigger) files ? The output in my intellij: 220 > 230 User logged in, proceed. 200 Type set to I. 250 Directory changed to /somedirectory null null java.lang.NullPointerException at org.apache.commons.net.SocketClient.getRemoteAddress(SocketClient.java:672) at org.apache.commons.net.ftp.FTPClient._openDataConnection_(FTPClient.java:819) at org.apache.commons.net.ftp.FTPClient._retrieveFileStream(FTPClient.java:1984) at org.apache.commons.net.ftp.FTPClient.retrieveFileStream(FTPClient.java:1971) at de.trustserv.jsfdl.app.sfdl.SFDLFileDownloader$DownloadRunnable.run(SFDLFileDownloader.java:145) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180) at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang.Thread.run(Thread.java:745)