Good morning, I'm trying to send an image from JAVA-ANDROID to a server via ftp, this is the code I'm using inside an asynchronous task
try {
FTPClient ftpClient = new FTPClient();
ftpClient.connect(InetAddress.getByName("ftp.miweb.com.co"));
ftpClient.login("[email protected]", "miclave");
ftpClient.changeWorkingDirectory("/micarpeta");
ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
BufferedInputStream buffIn = null;
buffIn = new BufferedInputStream(new FileInputStream("/storage/8ABF-1303/Download (1)/soda_stereo_03.jpeg"));
ftpClient.enterLocalPassiveMode();
ftpClient.storeFile("foto.jpg", buffIn);
buffIn.close();
ftpClient.logout();
ftpClient.disconnect();
} catch (Exception s) {
Log.i("consola", "Ups...");
return "false";
}
The problem is in this line, when trying to load the image from the Uri
buffIn = new BufferedInputStream(new FileInputStream("/storage/8ABF-1303/Download (1)/soda_stereo_03.jpeg"));
I get the following error in LOGCAT:
java.io.FileNotFoundException: /storage/8ABF-1303/Download (1)/soda_stereo_03.jpeg: open failed: EACCES (Permission denied)
At the end it says permission denied, these are my manifest permissions:
<uses-feature android:name="android.hardware.camera"
android:required="false">
</uses-feature>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.MANAGE_DOCUMENTS" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
I have researched for a long time and I have not found much about it, I hope you can help me, thanks
This is the tutorial I followed: http://androcode.es/2012/05/apache-commons-ftp-subiendo-archivos-a-servidores/
Although the error message indicates
FileNotFoundException
, it is actually a permissions problem:You should use:
instead of :
When requesting permission
WRITE_EXTERNAL_STORAGE
, the request is not necessaryREAD_EXTERNAL_STORAGE
.Remember that for devices with Android 6.0 or later, this request must be manual, I add this method that may help.