我制作了一个将简单的TXT文件上传到FTP服务器的APP。
错误:
不发布onProgressUpdate TV.setText,但会播放onPostExecute TV.setText。 (尚未解决)
不上传文件,没有报告错误,很快就完成了。 (通过解决下一个问题解决了)
说无法找到该文件。我猜这不是在/ res / raw中调用文件的方法。该文件确实存在。 - 解决了由coments提供的链接: -
InputStream FIS = getResources().openRawResource(getResources().getIdentifier("raw/wa", "raw", getPackageName()));-
代码
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