Newsletter sign-up
View all newsletters

Enterprise Java Newsletter
Stay up to date on the latest tutorials and Java community news posted on JavaWorld

JavaWorld Daily Brew

Problems with ftp transfers



hi all, i build a program that at start up need to upload from a ftp server some txt file.
I used the following code, sometimes it works, sometimes it get appended for about 15 min. ad return this error :
java.net.SocketException: Connection reset
at java.net.SocketInputStream.read(SocketInputStream.java:168)
at java.io.BufferedInputStream.read1(BufferedInputStream.java:256)
at java.io.BufferedInputStream.read(BufferedInputStream.java:317)
at java.io.BufferedInputStream.fill(BufferedInputStream.java:218)
at java.io.BufferedInputStream.read(BufferedInputStream.java:237)
at org.apache.commons.net.telnet.TelnetInputStream.__read(TelnetInputStream.java:104)
at org.apache.commons.net.telnet.TelnetInputStream.run(TelnetInputStream.java:520)
at java.lang.Thread.run(Thread.java:619)

import org.apache.commons.net.ftp.*;

public void connect (String server, String username,
String password,String fileCod ,String fileList)
{
try {
FTPClient ftp = new FTPClient();
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 dfile = new FileOutputStream("file.txt");
boolean b=ftp.retrieveFile(fileCod, dfile);
jTextField8.setText("codifica : "+b);
dfile.close();
ftp.logout();
ftp.disconnect();
} catch (SocketException ex) {
Logger.getLogger(Listino_101View.class.getName()).log (Level.SEVERE, null, ex);
System.exit(1);
} catch (IOException ex) {
Logger.getLogger(Listino_101View.class.getName()).log(Level.SEVERE, null, ex);
System.exit(1);
}
catch(Exception e)
{
System.exit(1);
}
}

Thanks.