This is a test version of Biostars. For the public version, visit https://www.biostars.org.
How To Download All Files In A Ftp Directory

Hi all, currently i can download only one file from the server, how do i download all the remaining files i want automatically using Java codes??

import java.io.*;

import java.net.URL;
import java.net.URLConnection;
import java.io.FileOutputStream;


public class ftp {

public static void main(String[] args) {

    try{

URL url =     new URL("ftp://ftp.wwpdb.org//pub//pdb//data//structures//all//pdb//pdb100d.ent.gz;type=d");
URLConnection con = url.openConnection();

BufferedInputStream in =     new BufferedInputStream(con.getInputStream());
FileOutputStream out =     new FileOutputStream("C:\\Users\\Royston\\Documents\\FTP downloads\\pdb100d.ent.gz");

int i = 0;
byte[] bytesIn = new byte[1024];

while ((i = in.read(bytesIn)) >= 0)
 {
out.write(bytesIn, 0, i);
 }
out.close();
in.close();
    } catch(Exception e)
        {
        e.printStackTrace();
        }    
    }   
}
download

It seems to me from your questions so far, that what you need is a good introductory guide to Java programming, rather than advice from a bioinformatics website. Also, as mentioned already, people will be more inclined to answer future questions if you give them credit for previous answers by selecting the best answer.

1 answer

  • Download list of complete PDB IDs from here
  • Parse full list of PDB IDs(first column)
  • Read up the IDs in a loop and replace 100d with each IDs.

If you could use shell/perl/python script you can get full data using fewer lines of code.

what if i need everything in that directory? is it able to work as well? because I dont really know how to go about doing it. If there're sample codes for me to work on it'll be a great help.

Log in to answer this question.