title: Android FTP Download
body: <p>I am using the following code segment to download a file to the SD Card of an Android phone. In the Wireshark trace I see the file is transferred and the FTP transfer complete message as well. But the file in the SD card is zero size. All required permissions are set in the manifest file. Can anybody help? Not working with FileOutputStream either.</p>
  
  <pre><code>       try{
         ftpClient.connect(InetAddress.getByName("xxx.xxx.xxx.xxx"));        
         ftpClient.login("xxxx", "xxxxx");
         ftpClient.changeWorkingDirectory("xxxx");
         ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
         ftpClient.enterLocalPassiveMode();
  
         //FileOutputStream desFileStream = new FileOutputStream("/sdcard/test25.txt");
         BufferedOutputStream desFileStream = new BufferedOutputStream(new FileOutputStream("/sdcard/test25.txt"),8*1024);
  
           boolean status=ftpClient.retrieveFile("test.txt", desFileStream);
  
           if(status){
          Toast toast = Toast.makeText(getApplicationContext(), "Downlaoded", Toast.LENGTH_SHORT);
          toast.show();
           }
  
         //desFileStream.flush();
  
         ftpClient.logout();
         ftpClient.disconnect();
  
         }
  
         catch (IOException e){
          Toast toast = Toast.makeText(getApplicationContext(), "Error", Toast.LENGTH_SHORT);
          toast.show();
          }
  </code></pre>