Note that there are some explanatory texts on larger screens.

plurals
  1. POError while trying to download a file via ftp on android
    primarykey
    data
    text
    <p>I am an amateur in android coding. I am trying to setup an android app with the ability to download a file from an ftp server. While running the code on the android 2.2 emulator, i am able to connect to the ftp server but the downloading part is showing an error. LogCat gives "download failed".</p> <pre><code>package com.ftconnect.down; import java.io.FileOutputStream; import android.app.Activity; import android.os.Bundle; import android.util.Log; import org.apache.commons.net.ftp.*; public class FTPConnectActivity extends Activity { /** Called when the activity is first created. */ public FTPClient mFTPClient = null; public boolean mConnect; public boolean mDownload; public boolean mDisconnected; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); mConnect = ftpConnect("xxx.xxx.xxx.xxx", "admin", "123456", 21); mDownload = ftpDownload("xxx.xxx.xxx.xxx/ftp.mp3", "/sdcard"); mDisconnected = ftpDisconnect(); } public boolean ftpConnect(String host, String username, String password, int port) { try { mFTPClient = new FTPClient(); // connecting to the host mFTPClient.connect(host, port); Log.d("ftpConnectApp", "Connecting to " + host); // now check the reply code, if positive mean connection success if (FTPReply.isPositiveCompletion(mFTPClient.getReplyCode())) { // login using username &amp; password boolean status = mFTPClient.login(username, password); return status; } } catch (Exception e) { Log.d("ftpConnectApp", "Error: could not connect to host " + host); } return false; } public boolean ftpDownload(String srcFilePath, String desFilePath) { boolean status = false; try { FileOutputStream desFileStream = new FileOutputStream(desFilePath); ; status = mFTPClient.retrieveFile(srcFilePath, desFileStream); desFileStream.close(); return status; } catch (Exception e) { Log.d("ftpConnectApp", "download failed"); } return status; } public boolean ftpDisconnect() { try { mFTPClient.logout(); mFTPClient.disconnect(); return true; } catch (Exception e) { Log.d("ftpConnectApp", "Error occurred while disconnecting from ftp server."); } return false; } } </code></pre> <p>I have setup the internet and write external permission in the android manifest file. Should i include any other permissions?</p> <p>Also, let me know if there is any changes to be made to the code above. Is the destination address as '/sdcard' correct?</p> <p>Thanks in advance.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload