title: How to download file from one Amazon EC2 instance to another EC2 instance using java apache FTPClient
body: <p>I have setup a ftp server in one amazon EC2 instance and can download file from that server in my local machine using apache ftp library. Now I am trying to run the same ftpclient program in another Amazon EC2 instance, but it is not working.
  Here is the sample code to download a file from ftpsever:</p>
  
  <pre><code>FTPClient ftp = new FTPClient();
  String loc = "/home/ubuntu/test/";
  String remote = "/home/ftp";
  try
  {
    ftp.connect("ec2-xx-xx-xx-xxx.compute-1.amazonaws.com", 21);
    ftp.login("username", "xxx");
    System.out.println("connected..");
    ftp.setFileType(FTP.BINARY_FILE_TYPE);
  
    OutputStream output;
    output = new FileOutputStream(loc+"file_name");
    ftp.retrieveFile(remote+"/filen_name", output);
    output.close();
    ftp.disconnect();
  }
  catch(Exception ex)
  {
     ex.printStackTrace();
  }
  </code></pre>
  
  <p>The following code can list all the file names of the remote directory:</p>
  
  <pre><code>for(FTPFile f: ftp.listFiles(remote))
  {
    System.out.println(f.getName());
  
  }
  </code></pre>
  
  <p>Both of the code work fine in my local machine but is not working in amazon machine. It connects but cannot list the file name or download file. And it doesn't show any error message.</p>
  
  <p>Thanks in advance--</p>