Abraham Putra Prakasa Abraham Putra Prakasa - 5 months ago 13
Android Question

Android FTP ChangeDirectory fail

I'm using ftp4j library to use FTPClient on android to upload text file from android to local network connected by Wifi.

If im not changing the directory then the default directory is

storage/emulated/0


But if i try
client.changeDirectory(Environment.getExternalStorageDirectory().getPath())
it catches Exception "failed to change directory". I want to upload the file from External Folder Directory such as DCIM, Downloads, Bluetooth folder (Just like when you browse your android from PC).

public void uploadFile(File fileName){
FTPClient client = new FTPClient();
try {
client.connect(ftpHostname);
client.login(ftpUsername, ftpPassword);
client.setType(FTPClient.TYPE_BINARY);
//client.changeDirectory(Environment.getExternalStorageDirectory().getPath());
client.upload(fileName);
notification = "The File Has Been Uploaded";
} catch (Exception e) {
Log.e("UploadFTP", e.toString());
notification = "Upload File Failed";

try {
client.disconnect(true);
} catch (Exception e2) {
Log.e("UploadFTPDC", e2.toString());
}
}
}


EDIT:

Seems like I'm confused with myself, After i log the getExternalStorageDirectory() it is returning
/storage/emulated/0/
so no need to change the directory.

Now the ftp4j Exception changed to "could not create file"

11-14 10:59:24.936: E/UploadFTP(1764): it.sauronsoftware.ftp4j.FTPException [code=553, message= Could not create file.]

Answer

You may have not write permission on the remote folder. Please check if the ftp user you logged in have a write permission on the directory. If not, give a write permission on it. If it unix like system try change permission like following command:

chmod +w folder