Error Encountered:Ftp Download Using Java Codes
I am writing a FTP program to download all the files from PDB FTP, however Im experiencing problem that I cannot solve. I can only download one file with the program which I build, it is actually supposed to download all the files in FTP. Can anyone tell me the error?
import java.io.FileReader;
import java.io.FileWriter;
import java.io.BufferedReader;
import java.io.PrintWriter;
import java.io.IOException;
import java.net.URL;
import java.net.URLConnection;
import java.io.FileOutputStream;
import java.io.*;
import java.util.*;
public class CopyLines {
public static StringBuffer buffer;
public static BufferedReader input;
public static void main(String[] args) throws IOException {
try {
URL url = new URL("ftp://ftp.wwpdb.org//pub//pdb//derived_data//pdb_entry_type.txt;type=i");
URLConnection con = url.openConnection();
BufferedInputStream in= new BufferedInputStream(con.getInputStream());
FileOutputStream out = new FileOutputStream("C:\Users\Royston\Documents\FTP downloads\pdb*entry*type.txt");
int i = 0;
byte[] bytesIn = new byte[1024];
while ((i = in.read(bytesIn)) >= 0) {
out.write(bytesIn, 0, i);
}
System.out.println("Download complete!!");
out.close();
in.close();
} catch (Exception e) {
e.printStackTrace();
}
BufferedReader inputStream = null; // scan input line by line
PrintWriter outputStream = null;// output aligned the same way
try {
inputStream = new BufferedReader(new FileReader("C:\\Users\\Royston\\Documents\\FTP downloads\\pdb_entry_type.txt"));
outputStream = new PrintWriter(new FileWriter("C:\\Users\\Royston\\Documents\\FTP downloads\\pdb.txt"));
String l;
while ((l = inputStream.readLine()) != null) {
outputStream.println(l);
}
} finally {
if (inputStream != null) {
inputStream.close();
}
if (outputStream != null) {
outputStream.close();
}
}
try {
input = new BufferedReader(
new FileReader( new File("C:\\Users\\Royston\\Documents\\FTP downloads\\pdb.txt") ) );
String text;
while ( ( text = input.readLine() ) != null ) {
StringTokenizer s = new StringTokenizer(text,"");
int counter=0;
while(s.hasMoreTokens()) {
String ss = s.nextToken();
counter++;
if (counter == 1 ) // extracts only 1st tokens per line.
System.out.print(ss + "\n");
URL url = new URL("ftp://ftp.wwpdb.org//pub//pdb//data//structures//all//pdb//pdb"+ss+".ent.gz;type=i");
URLConnection con = url.openConnection();
BufferedInputStream in= new BufferedInputStream(con.getInputStream());
FileOutputStream out = new FileOutputStream("C:\Users\Royston\Documents\FTP downloads\"+ss+".ent.gz");
int i = 0;
byte[] bytesIn = new byte[1024];
while ((i = in.read(bytesIn)) >= 0) {
out.write(bytesIn, 0, i);**
}
System.out.println("*****************************************************");
System.out.println("File Transfer Protocol Download complete!!");
System.out.println("File Transfer Protocol Download complete!!");
System.out.println("File Transfer Protocol Download complete!!");
System.out.println("File Transfer Protocol Download complete!!");
System.out.println("***************************************************");
out.close();
in.close();
}
}
System.out.println();
} catch( IOException ioException ) {}
}
}
• 440 views
•
link
0 answers
No answers yet.
Log in to answer this question.
Closed. How To Convert Gz File To Pdb Format?
Agreed. This user keeps posting minor variations of the same question and persistently refuses to acknowledge helpful answers.