Ciao a tutti, cerco aiuto per un problema :
ho una classe che scarica un file txt da un server ftp.
Funziona spesso, ma a volte rimane appesa e devo uscire forzatamente dall'applicazione.
Credo che il problema sia tra il metodo "retrieveFile" e w. firewall.
Con vista va meglio che con xp.
Mi servirebbe anche un metodo per poter annullare l'operazione senza uscire dall'applicazione.
import org.apache.commons.net.ftp.FTP;
import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.net.ftp.FTPReply;
public void aggiorna (String server, String username,
String password,String fileToTransfer)
{
try {
FTPClient ftp = new FTPClient();
ftp.enterLocalPassiveMode();
ftp.connect(server, 21);
ftp.login(username, password);
String risposta=ftp.getReplyString();
System.out.println("risposta :" +risposta);
int reply;
reply = ftp.getReplyCode();
System.out.println("reply " +reply);
if (!FTPReply.isPositiveCompletion(reply))
{
System.out.println("reply negativa " +reply);
}
else{
System.out.println("reply positiva " +reply);
ftp.setFileType(FTP.BINARY_FILE_TYPE);
FileOutputStream lfile = new FileOutputStream("file.txt");
boolean c=ftp.retrieveFile(fileToTransfer, lfile);
System.out.println("file scaricato :"+c);
lfile.close();
ftp.logout();
ftp.disconnect();
System.out.println("disconnesso");
}
} catch (SocketException ex) {
Logger.getLogger(FTP_modulo_3View.class.getName()) .log(Level.SEVERE, null, ex);
System.exit(1);
} catch (IOException ex) {
Logger.getLogger(FTP_modulo_3View.class.getName()) .log(Level.SEVERE, null, ex);
System.exit(1);
}
catch(Exception e)
{
System.exit(1);
}
}
Grazie : )

Rispondi quotando

