I created program in java. which reads files from several ftp servers. But it reads first file by bufferreader and second time occures NullPointerException. Here is my code:
while(true){//READ .CSV AND WRITE TO DB
client=new FTPClient();
try {
client.connect(ftps.getIp());
client.enterLocalActiveMode();
client.login(ftps.getLogin(),ftps.getPassword());
System.out.println("Connected with ftp "+ftps.getName());
String[] files = client.listNames();
InputStream ins;
BufferedReader bf;
for(int i=0;i<files.length;i++){
ins=client.retrieveFileStream(files[i]);
bf= new BufferedReader(new InputStreamReader(ins));
try {
String str = "";
do
{
lines.add(str);
str = bf.readLine();
} while (!str.equals(null));
}catch (NullPointerException ex){
}
catch (Exception ex){
System.out.println("Error while reading file "+files[i]+" from ftp "+ftps.getName()+" ERROR "+ex.toString());
}
finally {
bf.close();
}
}
} catch (Exception e) {
System.out.println("Error in executing ftp "+ftps.getName()+e.toString());
}finally {
if(client.isConnected())
try{
client.disconnect();
}catch (Exception ex){
System.out.println("Error while disconnecting with ftp "+ftps.getName());
}
System.out.println("Disconnected with ftp "+ftps.getName());
}
Error in executing ftp ftpserver's name appeares in console.