I've made an APP that Uploads a simple TXT file to a FTP server.
Errors:
Doesn't publish the onProgressUpdate TV.setText but pulbishes the onPostExecute TV.setText. (Not yet resolved)
Doesn't upload the file, no error reported, finishes very quickly. (Solved, by solving next problem)
Says it can't find the file. I'm guessing that this is not the way to call a file in /res/raw. The file does exist. -Solved with link provided by coments use:-
InputStream FIS = getResources().openRawResource(getResources().getIdentifier("raw/wa", "raw", getPackageName()));-
Code
private class AsyncFTP extends AsyncTask<String, String, String>{
@Override
protected String doInBackground(String... params) {
publishProgress("Start");
//Creo FTPClient
FTPClient FTP = new FTPClient();
//Defino datos del servidor
String FTP_HOST = "000.000.000.000"; //Not real IP
String FTP_USER = "usuer";
String FTP_PASS = "pass";
//Cargo el archivo
File file = new File("res/raw/asd.txt");
publishProgress("File selected");
//Conectar
try{
publishProgress("Conecting ");
FTP.connect(FTP_HOST,21);
FTP.login(FTP_USER,FTP_PASS);
publishProgress("Conected "+String.valueOf(FTP.getReplyCode()));
FTP.type(FTPClient.BINARY_FILE_TYPE);
//Directorio
FTP.changeWorkingDirectory("/public_html/");
publishProgress("Dir "+String.valueOf(FTP.getReplyCode()));
FileInputStream FIS = new FileInputStream(file); //ENOENT (No such file or directory)
FTP.enterLocalPassiveMode();
FTP.storeFile("asd.txt",FIS);
publishProgress("Subio"+String.valueOf(FTP.getReplyCode()));
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
protected void onProgressUpdate(String txt) {
TV.setText(TV.getText()+"\n"+txt);
}
@Override
protected void onPostExecute(String result){
TV.setText(TV.getText()+"\n Termino FTP");
}
}
Logcat
OpenGL ES Shader Compiler Version: 17.01.12.SPL
Build Date: 07/01/14 Tue
Local Branch:
Remote Branch: quic/kk_2.7_rb1.41
Local Patches: NONE
Reconstruct Branch: AU_LINUX_ANDROID_KK_2.7_RB1.04.04.04.007.064 + NOTHING
12-15 12:20:20.110 5701-5701/com.lstupenengo.mysql D/OpenGLRenderer﹕ Enabling debug mode 0
12-15 12:20:20.240 5701-5701/com.lstupenengo.mysql I/ActivityManager﹕ Timeline: Activity_idle id: android.os.BinderProxy@44bcc450 time:294619278
12-15 12:20:23.193 5701-5701/com.lstupenengo.mysql I/ActivityManager﹕ Timeline: Activity_idle id: android.os.BinderProxy@44bcc450 time:294622220
12-15 12:20:36.876 5701-5701/com.lstupenengo.mysql I/ActivityManager﹕ Timeline: Activity_idle id: android.os.BinderProxy@44bcc450 time:294635918
12-15 12:20:38.938 5701-6070/com.lstupenengo.mysql W/System.err﹕ java.io.FileNotFoundException: /res/raw/wa.db: open failed: ENOENT (No such file or directory)
12-15 12:20:38.938 5701-6070/com.lstupenengo.mysql W/System.err﹕ at libcore.io.IoBridge.open(IoBridge.java:418)
12-15 12:20:38.938 5701-6070/com.lstupenengo.mysql W/System.err﹕ at java.io.FileInputStream.<init>(FileInputStream.java:78)
12-15 12:20:38.938 5701-6070/com.lstupenengo.mysql W/System.err﹕ at com.lstupenengo.mysql.MainActivity$AsyncFTP.doInBackground(MainActivity.java:100)
12-15 12:20:38.948 5701-6070/com.lstupenengo.mysql W/System.err﹕ at com.lstupenengo.mysql.MainActivity$AsyncFTP.doInBackground(MainActivity.java:71)
12-15 12:20:38.948 5701-6070/com.lstupenengo.mysql W/System.err﹕ at android.os.AsyncTask$2.call(AsyncTask.java:288)
12-15 12:20:38.948 5701-6070/com.lstupenengo.mysql W/System.err﹕ at java.util.concurrent.FutureTask.run(FutureTask.java:237)
12-15 12:20:38.948 5701-6070/com.lstupenengo.mysql W/System.err﹕ at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
12-15 12:20:38.948 5701-6070/com.lstupenengo.mysql W/System.err﹕ at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
12-15 12:20:38.958 5701-6070/com.lstupenengo.mysql W/System.err﹕ at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
12-15 12:20:38.958 5701-6070/com.lstupenengo.mysql W/System.err﹕ at java.lang.Thread.run(Thread.java:841)
12-15 12:20:38.958 5701-6070/com.lstupenengo.mysql W/System.err﹕ Caused by: libcore.io.ErrnoException: open failed: ENOENT (No such file or directory)
12-15 12:20:38.958 5701-6070/com.lstupenengo.mysql W/System.err﹕ at libcore.io.Posix.open(Native Method)
12-15 12:20:38.958 5701-6070/com.lstupenengo.mysql W/System.err﹕ at libcore.io.BlockGuardOs.open(BlockGuardOs.java:110)
12-15 12:20:38.968 5701-6070/com.lstupenengo.mysql W/System.err﹕ at libcore.io.IoBridge.open(IoBridge.java:402)
12-15 12:20:38.968 5701-6070/com.lstupenengo.mysql W/System.err﹕ ... 9 more
12-15 12:20:48.007 5701-5701/com.lstupenengo.mysql I/ActivityManager﹕ Timeline: Activity_idle id: android.os.BinderProxy@44bcc450 time:294647049
12-15 12:21:16.084 5701-5701/com.lstupenengo.mysql I/ActivityManager﹕ Timeline: Activity_idle id: android.os.BinderProxy@44bcc450 time:294675123