This is a test version of Biostars. For the public version, visit https://www.biostars.org.
How To Download From Pdb (Ftp)Website Using Java Codes?

Hi all, I am doing a project on downloading of protein files from pdb (ftp)website by using java codes. Does anyone know how I can go about doing this?

pdb

3 answers

See Read from URL

If you can use non Java solution, you may take a look at the FTP page at PDB. If you are looking to download complete data, PDB provides shell scripts to download and maintain PDB files. One of the script use rsync for the download.

hi khader, im sorry to say that I can only use java to go about downloading the files from there. Are there any source of help that I can get from anywhere?

I am sure that you can call the system commands from Java using run time execution function(I use system or `` in Perl) in Java. As the ftp script provided by RCSB is in shell script, you may easily call them via your Java program.

Here is the suitable Java code fragment. It reads from URL and saves to some location on the local folder.

URL u = new URL("http://.....");
InputStream in = url.openStream();
byte [] buffer = new byte[4024];
int n;
FileOutputStream out = new FileOutputStream("...");
// Read at most buffer.length bytes into buffer, returns the number of bytes actually read or -1 on eof.
while ( (n = in.read(buffer)) > 0) {
    // Only write  the newly read bytes. 
    out.write(buffer, 0, n);
 }
out.close();
in.close();

Log in to answer this question.