0

Based on an answer on this thread, we can upload and download from FTP server:

//UPLOAD
try
{
    FTPClient con = new FTPClient();
    con.connect("192.168.2.57");

    if (con.login("Administrator", "KUjWbk"))
    {
        con.enterLocalPassiveMode(); // important!
        con.setFileType(FTP.BINARY_FILE_TYPE);
        String data = "/sdcard/vivekm4a.m4a";

        FileInputStream in = new FileInputStream(new File(data));
        boolean result = con.storeFile("/vivekm4a.m4a", in);
        in.close();
        if (result) Log.v("upload result", "succeeded");
            con.logout();
            con.disconnect();
        }
    }
catch (Exception e)
{
    e.printStackTrace();
}

//DOWNLOAD
try
{
    FTPClient con = new FTPClient();
    con.connect("192.168.2.57");

    if (con.login("Administrator", "KUjWbk"))
    {
        con.enterLocalPassiveMode(); // important!
        con.setFileType(FTP.BINARY_FILE_TYPE);
        String data = "/sdcard/vivekm4a.m4a";

        OutputStream out = new FileOutputStream(new File(data));
        boolean result = con.retrieveFile("vivekm4a.m4a", out);
        out.close();
        if (result) Log.v("download result", "succeeded");
        con.logout();
        con.disconnect();
    }
}
catch (Exception e)
{
    Log.v("download result","failed");
    e.printStackTrace();
}

In download part, is it possible to just retrieve the file (assuming the file is always jpg) and convert it to Bitmap without having to create a file in my application's folder?

Community
  • 1
  • 1
Hendra Anggrian
  • 5,780
  • 13
  • 57
  • 97

1 Answers1

1

You can use picaso library to get the image downloaded from FTP server and obtain its bitmap.
Picasso library has special method "target" which will directly provide you the downloaded bitmap for you code.
Hope it will help you. e.g

Target target = new Target() {
      @Override
      public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {       
       // You can use the bitmap object here
      }
      @Override
      public void onBitmapFailed() {
      }
}
 Picasso.with(this).load("url").into(target);
Ichigo Kurosaki
  • 3,765
  • 8
  • 41
  • 56