javaandroidftpapache-commons-net

FTP upload does not work Android


I am trying to upload a picture from a Samsung to an FTP server using the Apache FTPClient. But it does not seem to work. I don't know why, the code is fine. I am trying to choose an image to upload it on the server, the selectedImage variable is the complete path of the picture file.

FTPClient ftpClient = new FTPClient();
ftpClient.connect(InetAddress.getByName("ftpserver"));
ftpClient.login("user", "password");
ftpClient.setFileType(FTP.BINARY_FILE_TYPE);

FileInputStream buffIn = null;
buffIn = new FileInputStream(new File(getRealPathFromURI(selectedImage)));
ftpClient.enterLocalPassiveMode();
link = "http://ftpname/home/user/public_html/image/ayri.jpg";
ftpClient.storeFile(link, buffIn);
buffIn.close();
ftpClient.logout();
ftpClient.disconnect();

Solution

  • So i've found myself the answer, for those of you who will encounter this problem, first for POST or UPLOADING files, always use Asynctask, if not it will never work. And just check that in your application you have permission for file management, you can see in settings -> Application -> Your app -> Permission -> Storage check yes. And that's it.

    Thank you stackoverflow for helping !