FTPclient is driving me nuts! please advise!
Hi all,
I am currently working on a project which involves the Edgar SEC database (a public database owned by the USA gov. see link for explanation: Information for FTP Users ). I am trying to download certain files from it using FTPclient but it is not working! Eclipse returns the following code when i run the script. I have googled arround and did not found a conclusive answer. Please have a look and give me some suggestions!:=(:
Code:
java.net.SocketException: Software caused connection abort: recv failed
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.read(Unknown Source)
at java.net.SocketInputStream.read(Unknown Source)
at sun.nio.cs.StreamDecoder.readBytes(Unknown Source)
at sun.nio.cs.StreamDecoder.implRead(Unknown Source)
at sun.nio.cs.StreamDecoder.read(Unknown Source)
at java.io.InputStreamReader.read(Unknown Source)
at java.io.BufferedReader.fill(Unknown Source)
at java.io.BufferedReader.read(Unknown Source)
at org.apache.commons.net.io.CRLFLineReader.readLine(CRLFLineReader.java:58)
at org.apache.commons.net.ftp.FTP.__getReply(FTP.java:310)
at org.apache.commons.net.ftp.FTP.__getReply(FTP.java:290)
at org.apache.commons.net.ftp.FTP.sendCommand(FTP.java:474)
at org.apache.commons.net.ftp.FTP.sendCommand(FTP.java:547)
at org.apache.commons.net.ftp.FTP.port(FTP.java:872)
at org.apache.commons.net.ftp.FTPClient._openDataConnection_(FTPClient.java:667)
at org.apache.commons.net.ftp.FTPClient.initiateListParsing(FTPClient.java:2990)
at org.apache.commons.net.ftp.FTPClient.initiateListParsing(FTPClient.java:2965)
at org.apache.commons.net.ftp.FTPClient.listFiles(FTPClient.java:2623)
at org.apache.commons.net.ftp.FTPClient.listFiles(FTPClient.java:2670)
at NERV.initiateNerv.alternativeFTP(initiateNerv.java:615)
at NERV.initiateNerv.main(initiateNerv.java:646)
Code:
import org.apache.commons.net.ftp.FTP;
import org.apache.commons.net.ftp.FTPFile;
import org.apache.commons.net.ftp.FTPClient;
private static void FTP(){
String edgarServer ="ftp.sec.gov";
String directory = "//edgar";
try {
FTPClient edgarFTP = new FTPClient();
int reply;
edgarFTP.connect(edgarServer);
edgarFTP.setRemoteVerificationEnabled(false);
System.out.println("Connected to EDGAR");
System.out.print(edgarFTP.getReplyString());
reply = edgarFTP.getReplyCode();
if(!FTPReply.isPositiveCompletion(reply)) {
edgarFTP.disconnect();
System.err.println("FTP server refused connection.");
System.exit(1);
}
FileOutputStream fos = null;
String filename = "README.txt";
fos = new FileOutputStream("C:\\"+filename);
edgarFTP.retrieveFile(directory+"/" + filename, fos); //pull ftp.sec.gov/edgar/README.txt (it does nothing at all..)
FTPFile[] files = edgarFTP.listFiles(); //list all files (returns the error as mentioned above)
edgarFTP.logout();
edgarFTP.disconnect();
} catch(IOException e) {
error = true;
e.printStackTrace();
}
}
Re: FTPclient is driving me nuts! please advise!
The stack trace does not seem to show any references to your code.