このコードは現在機能しています。LogCatは、他のpplからのリードバックの問題にのみ使用されます
破損することなくFTPサーバーからファイル(ダウンロードしたファイル)をダウンロードするにはどうすればよいですか?ファイルをダウンロードできますが、バイト数が0です。
しかし、すべて同じ.txt、.png、.exe、.apkファイルは、私の電話では毎回破損/読み取り不能(0バイト)です。たとえば、私のftpサーバーにinit.txtというファイル(次のテキストが含まれています: "testfileini !!")の場合、そのサイズはftpでは13バイト、電話では0バイトです。
OnItemClickListener(ftpファイルリストからファイルを直接選択するため)
lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
String file = (String) lv.getItemAtPosition(position);
new DownloadFile().execute(file);
}
});
AsyncTask Downloadfile(バックグラウンドでダウンロードするため)
private class DownloadFile extends AsyncTask<String, Integer, String> {
@Override
protected String doInBackground(String... filename) {
try {
System.out.println("Filename->: " + filename[0]);
GetFileFTP("/subdomains/giveyourapps/httpdocs/apps/"+filename[0], Environment.getExternalStorageDirectory() + "/Download/", filename[0]);
} finally {
disconnectFTP();
}
return null;
}
}
GetFileFTP
public void GetFileFTP(String srcFileSpec, String destpath, String destname) {
FTPClient client = new FTPClient();
Log.v("pathSpec: ", destpath);
try {
client.connect("176.28.25.46");
client.login("ftp031220", "hSigSf");
client.enterLocalPassiveMode();
client.setFileType(org.apache.commons.net.ftp.FTP.BINARY_FILE_TYPE);
InputStream input = client.retrieveFileStream(srcFileSpec);
if(input != null) Log.v("GetFileFTP: ", "Input Stream Opened successfully");
Log.v("Fileinputstream: ", srcFileSpec);
File output_file = new File(destpath + destname);
Log.v("OUTPUTFILE: ", destpath + destname);
inputstreamcopy(input, output_file);
disconnectFTP();
}catch (IOException e) {
Log.e("FTP", "Error Getting File");
e.printStackTrace();
}
}
copyInputStreamToFile
public static void inputstreamcopy(InputStream source,
File destination){
try {
org.apache.commons.io.FileUtils.copyInputStreamToFile(source, destination);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
LogCat
11-07 15:09:08.675: D/GestureDetector(15746): [Surface Touch Event] mSweepDown False, mLRSDCnt : -1 mTouchCnt : 3 mFalseSizeCnt:0
11-07 15:09:08.905: I/System.out(15746): status :: 211-Status of 'ProFTPD'
11-07 15:09:08.905: I/System.out(15746): Connected from 109.164.221.167 (109.164.221.167)
11-07 15:09:08.905: I/System.out(15746): Logged in as ftp031220
11-07 15:09:08.905: I/System.out(15746): TYPE: BINARY, STRUcture: File, Mode: Stream
11-07 15:09:08.905: I/System.out(15746): No data connection
11-07 15:09:08.910: I/System.out(15746): 211 End of status
11-07 15:09:09.025: D/dalvikvm(15746): GC_CONCURRENT freed 93K, 10% free 12464K/13703K, paused 15ms+12ms, total 58ms
11-07 15:09:09.390: I/System.out(15746): Files->: 1Tap_Cleaner_Pro_v1.45.apk
11-07 15:09:09.390: I/System.out(15746): Files->: AppBrain_App_Market_v7.5.apk
11-07 15:09:09.395: I/System.out(15746): Files->: Apparatus_v1.0.4_ADFREE_ANDROiD-P2P.apk
11-07 15:09:09.395: I/System.out(15746): Files->: Atomic_Bomber_5.0.apk
11-07 15:09:09.395: I/System.out(15746): Files->: IMG_20120917_120935.jpg
11-07 15:09:09.395: I/System.out(15746): Files->: init.txt
11-07 15:09:09.395: I/System.out(15746): Files->: unnamed.png
11-07 15:09:09.500: E/SpannableStringBuilder(15746): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
11-07 15:09:09.500: E/SpannableStringBuilder(15746): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
11-07 15:09:13.805: D/GestureDetector(15746): [Surface Touch Event] mSweepDown False, mLRSDCnt : -1 mTouchCnt : 2 mFalseSizeCnt:0
11-07 15:09:13.880: I/System.out(15746): Filename->: init.txt
11-07 15:09:13.880: V/pathSpec:(15746): /storage/sdcard0/Download/
11-07 15:09:14.310: V/GetFileFTP:(15746): Input Stream Opened successfully
11-07 15:09:14.310: V/Fileinputstream:(15746): /subdomains/giveyourapps/httpdocs/apps/init.txt
11-07 15:09:14.310: V/OUTPUTFILE:(15746): /storage/sdcard0/Download/outputfile.txt
11-07 15:09:14.310: I/dalvikvm(15746): threadid=11: stack overflow on call to Lcom/mseiz/give/your/apps/MainSite;.copyInputStreamToFile:VLL
11-07 15:09:14.310: I/dalvikvm(15746): method requires 8+20+8=36 bytes, fp is 0x5ec4b310 (16 left)
11-07 15:09:14.310: I/dalvikvm(15746): expanding stack end (0x5ec4b300 to 0x5ec4b000)
11-07 15:09:14.315: I/dalvikvm(15746): Shrank stack (to 0x5ec4b300, curFrame is 0x5ec4eeb0)
11-07 15:09:14.315: W/dalvikvm(15746): threadid=11: thread exiting with uncaught exception (group=0x40d9f2a0)
11-07 15:09:14.375: D/dalvikvm(15746): GC_CONCURRENT freed 283K, 10% free 12654K/14023K, paused 14ms+11ms, total 47ms
11-07 15:09:14.405: D/dalvikvm(15746): GC_FOR_ALLOC freed 314K, 11% free 12682K/14215K, paused 10ms, total 10ms
11-07 15:09:14.405: E/AndroidRuntime(15746): FATAL EXCEPTION: AsyncTask #1
11-07 15:09:14.405: E/AndroidRuntime(15746): java.lang.RuntimeException: An error occured while executing doInBackground()
11-07 15:09:14.405: E/AndroidRuntime(15746): at android.os.AsyncTask$3.done(AsyncTask.java:299)
11-07 15:09:14.405: E/AndroidRuntime(15746): at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
11-07 15:09:14.405: E/AndroidRuntime(15746): at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
11-07 15:09:14.405: E/AndroidRuntime(15746): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
11-07 15:09:14.405: E/AndroidRuntime(15746): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
11-07 15:09:14.405: E/AndroidRuntime(15746): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
11-07 15:09:14.405: E/AndroidRuntime(15746): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
11-07 15:09:14.405: E/AndroidRuntime(15746): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
11-07 15:09:14.405: E/AndroidRuntime(15746): at java.lang.Thread.run(Thread.java:856)
11-07 15:09:14.405: E/AndroidRuntime(15746): Caused by: java.lang.StackOverflowError
11-07 15:09:14.405: E/AndroidRuntime(15746): at com.mseiz.give.your.apps.MainSite.copyInputStreamToFile(MainSite.java:119)
11-07 15:09:14.405: E/AndroidRuntime(15746): at com.mseiz.give.your.apps.MainSite.copyInputStreamToFile(MainSite.java:119)
11-07 15:09:14.405: E/AndroidRuntime(15746): at com.mseiz.give.your.apps.MainSite.copyInputStreamToFile(MainSite.java:119)
11-07 15:09:14.405: E/AndroidRuntime(15746): at com.mseiz.give.your.apps.MainSite.copyInputStreamToFile(MainSite.java:119)
11-07 15:09:14.405: E/AndroidRuntime(15746): at com.mseiz.give.your.apps.MainSite.copyInputStreamToFile(MainSite.java:119)
11-07 15:09:14.405: E/AndroidRuntime(15746): at com.mseiz.give.your.apps.MainSite.copyInputStreamToFile(MainSite.java:119)
11-07 15:09:14.405: E/AndroidRuntime(15746): at com.mseiz.give.your.apps.MainSite.copyInputStreamToFile(MainSite.java:119)
11-07 15:09:14.405: E/AndroidRuntime(15746): at com.mseiz.give.your.apps.MainSite.copyInputStreamToFile(MainSite.java:119)
11-07 15:09:14.405: E/AndroidRuntime(15746): at com.mseiz.give.your.apps.MainSite.copyInputStreamToFile(MainSite.java:119)
11-07 15:09:14.405: E/AndroidRuntime(15746): at com.mseiz.give.your.apps.MainSite.copyInputStreamToFile(MainSite.java:119)
11-07 15:09:14.405: E/AndroidRuntime(15746): at com.mseiz.give.your.apps.MainSite.copyInputStreamToFile(MainSite.java:119)
11-07 15:09:14.405: E/AndroidRuntime(15746): at com.mseiz.give.your.apps.MainSite.copyInputStreamToFile(MainSite.java:119)
11-07 15:09:14.405: E/AndroidRuntime(15746): at com.mseiz.give.your.apps.MainSite.copyInputStreamToFile(MainSite.java:119)
11-07 15:09:14.405: E/AndroidRuntime(15746): at com.mseiz.give.your.apps.MainSite.copyInputStreamToFile(MainSite.java:119)
11-07 15:09:14.405: E/AndroidRuntime(15746): at com.mseiz.give.your.apps.MainSite.copyInputStreamToFile(MainSite.java:119)
11-07 15:09:14.405: E/AndroidRuntime(15746): at com.mseiz.give.your.apps.MainSite.copyInputStreamToFile(MainSite.java:119)
11-07 15:09:14.405: E/AndroidRuntime(15746): at com.mseiz.give.your.apps.MainSite.copyInputStreamToFile(MainSite.java:119)
11-07 15:09:14.405: E/AndroidRuntime(15746): at com.mseiz.give.your.apps.MainSite.copyInputStreamToFile(MainSite.java:119)
11-07 15:09:14.405: E/AndroidRuntime(15746): at com.mseiz.give.your.apps.MainSite.copyInputStreamToFile(MainSite.java:119)
11-07 15:09:14.405: E/AndroidRuntime(15746): at com.mseiz.give.your.apps.MainSite.copyInputStreamToFile(MainSite.java:119)
11-07 15:09:14.405: E/AndroidRuntime(15746): at com.mseiz.give.your.apps.MainSite.copyInputStreamToFile(MainSite.java:119)
11-07 15:09:14.405: E/AndroidRuntime(15746): at com.mseiz.give.your.apps.MainSite.copyInputStreamToFile(MainSite.java:119)
11-07 15:09:14.405: E/AndroidRuntime(15746): at com.mseiz.give.your.apps.MainSite.copyInputStreamToFile(MainSite.java:119)
11-07 15:09:14.405: E/AndroidRuntime(15746): at com.mseiz.give.your.apps.MainSite.copyInputStreamToFile(MainSite.java:119)
11-07 15:09:14.405: E/AndroidRuntime(15746): at com.mseiz.give.your.apps.MainSite.copyInputStreamToFile(MainSite.java:119)
11-07 15:09:14.405: E/AndroidRuntime(15746): at com.mseiz.give.your.apps.MainSite.copyInputStreamToFile(MainSite.java:119)
11-07 15:09:14.405: E/AndroidRuntime(15746): at com.mseiz.give.your.apps.MainSite.copyInputStreamToFile(MainSite.java:119)
11-07 15:09:14.405: E/AndroidRuntime(15746): at com.mseiz.give.your.apps.MainSite.copyInputStreamToFile(MainSite.java:119)
11-07 15:09:14.405: E/AndroidRuntime(15746): at com.mseiz.give.your.apps.MainSite.copyInputStreamToFile(MainSite.java:119)
11-07 15:09:14.405: E/AndroidRuntime(15746): at com.mseiz.give.your.apps.MainSite.copyInputStreamToFile(MainSite.java:119)
11-07 15:09:14.405: E/AndroidRuntime(15746): at com.mseiz.give.your.apps.MainSite.copyInputStreamToFile(MainSite.java:119)
11-07 15:09:14.405: E/AndroidRuntime(15746): at com.mseiz.give.your.apps.MainSite.copyInputStreamToFile(MainSite.java:119)
11-07 15:09:14.405: E/AndroidRuntime(15746): at com.mseiz.give.your.apps.MainSite.copyInputStreamToFile(MainSite.java:119)
11-07 15:09:14.405: E/AndroidRuntime(15746): at com.mseiz.give.your.apps.MainSite.copyInputStreamToFile(MainSite.java:119)
11-07 15:09:14.405: E/AndroidRuntime(15746): at com.mseiz.give.your.apps.MainSite.copyInputStreamToFile(MainSite.java:119)
11-07 15:09:14.405: E/AndroidRuntime(15746): at com.mseiz.give.your.apps.MainSite.copyInputStreamToFile(MainSite.java:119)
11-07 15:09:14.405: E/AndroidRuntime(15746): at com.mseiz.give.your.apps.MainSite.copyInputStreamToFile(MainSite.java:119)
11-07 15:09:14.405: E/AndroidRuntime(15746): at com.mseiz.give.your.apps.MainSite.copyInputStreamToFile(MainSite.java:119)
11-07 15:09:14.405: E/AndroidRuntime(15746): at com.mseiz.give.your.apps.MainSite.copyInputStreamToFile(MainSite.java:119)
11-07 15:09:14.405: E/AndroidRuntime(15746): at com.mseiz.give.your.apps.MainSite.copyInputStreamToFile(MainSite.java:119)
11-07 15:09:14.405: E/AndroidRuntime(15746): at com.mseiz.give.your.apps.MainSite.copyInputStreamToFile(MainSite.java:119)
11-07 15:09:14.405: E/AndroidRuntime(15746): at com.mseiz.give.your.apps.MainSite.copyInputStreamToFile(Ma
11-07 15:09:14.420: D/dalvikvm(15746): GC_CONCURRENT freed 553K, 12% free 12644K/14343K, paused 2ms+2ms, total 12ms
11-07 15:09:14.420: D/dalvikvm(15746): WAIT_FOR_CONCURRENT_GC blocked 9ms
11-07 15:09:14.440: D/dalvikvm(15746): GC_CONCURRENT freed 324K, 11% free 12802K/14343K, paused 1ms+2ms, total 17ms