私はアンドロイドとJavaのプログラミングが初めてです。私はftpサーバーに接続するために次のコードを書きます
public class NewMainActivity extends Activity {
TextView Display;
//declare a public FTP client object.
public FTPClient mFTPClient = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_new_main);
final TextView Display = (TextView) findViewById(R.id.tvResults);
try {
mFTPClient = new FTPClient();
// connecting to the host
mFTPClient.connect("www.filegenie.com",21);
// now check the reply code, if positive mean connection success
if (FTPReply.isPositiveCompletion(mFTPClient.getReplyCode())) {
// login using username & password
boolean status = mFTPClient.login("user", "MyPassword");
// Set File Transfer Mode
mFTPClient.setFileType(FTP.BINARY_FILE_TYPE);
mFTPClient.enterLocalPassiveMode();
Display.setText("Correct"+ String.valueOf(status)); //return status;
}
}catch(Exception e) {
Display.setText(" Exception message is = "+e.getMessage()+" Reply code = "+mFTPClient.getReplyCode());
}
}
このコードを実行すると、特定のエラーは発生しませんが、プログラムは mFTPClient.connect メソッドを実行せず、「Exception」部分にジャンプし、例外 getMessage として「null」、ReplyCode として「0」を取得します。次のような必要なすべてのファイルをインポートしました
import org.apache.commons.net.ftp.FTP;
import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.net.ftp.FTPReply;
私はEclipseとADT Build v22.0.1-685705を使用しています。また、android プロジェクトの lib に commons-net-3.3、commons-net-3.3-sources、および commons-net-examples-3.3 ファイルを含め、commons-net-3.3-src の Java ファイルとフォルダーも含めました。ソース | メイン | ジャバ | 組織 | アパッチ | コモンズ | フォルダー org | を作成して、net フォルダーを Android プロジェクトの src フォルダーに移動します。アパッチ | コモンズ | ネット。何が問題なのかわかりませんでした。この点で誰でも私を助けることができますか?
商用ftpクライアントでも同じサーバーにアクセスできます。
前もって感謝します。