I have a list of channels in the database that I use to download an XML file from an FTP server, and then parse it. The script is inserted into the jar file, which is run daily using the Windows task manager. Sometimes a request occurs when capturing a specific XML file. Until now, this has happened about 3 times in 2 weeks without the real picture that I see.
When this goes bad, I go to the computer on which it runs, I see that the command window is open, and it stopped before the xml was fully loaded. If I close the command window and run the task manually, everything will work fine.
The code I use to download the xml file is:
private void loadFTPFile(String host, String username, String password, String filename, String localFilename){ System.out.println(localFilename); FTPClient client = new FTPClient(); FileOutputStream fos = null; try { client.connect(host); client.login(username, password); String localFilenameOutput = createFile(assetsPath + localFilename); fos = new FileOutputStream(localFilenameOutput); client.retrieveFile(filename, fos); } catch (IOException e) { e.printStackTrace(); } finally { try { if (fos != null) fos.close(); client.disconnect(); } catch (IOException e) { e.printStackTrace(); } } }
This function is called in a loop, and when it fails, everything stops, and the script does not go to the next channel.
I'm not sure what is happening, possibly a loss of connection, but I think the / catch attempt will catch if that happens. I'm not sure if the timeout will use a trick or threads (but I have never worked with threads)
Can someone point me in the right direction on why this is happening and what I can do to fix the problem.
source share