以下代码在pc上测试通过,可是在android模拟器上就不工作,不过还可以链接到服务器但不能得到文件 纠结了半天,原来是模式的问题,具体请Google 模拟器中采用建议被动模式

public void getWorkMessage(){  

    FTPClient ftp = new FTPClient();  

    try {
ftp.connect(server); System.out.println("Connected to " + server);
System.out.print(ftp.getReplyString()); reply = ftp.getReplyCode(); if(!FTPReply.isPositiveCompletion(reply)) {
ftp.disconnect();
System.err.println("FTP server refused connection.");
System.exit(1);
}
ftp.login(username, password); FTPFile[] files = ftp.listFiles("/"); if(files!=null&&files.length>0){ for(FTPFile f:files){ System.out.println("user:>>>"+f.getUser()+" name:>>>"+f.getName()+" size:>>>"+f.getSize()+" link:>>>"+f.getLink()); }
}
} catch (SocketException e) { e.printStackTrace();
} catch (IOException e) { e.printStackTrace();
} }

加上被动模式之后,代码如下:

public void getWorkMessage(){  

        FTPClient ftp = new FTPClient();  

        try {
ftp.connect(server); System.out.println("Connected to " + server);
System.out.print(ftp.getReplyString()); reply = ftp.getReplyCode(); if(!FTPReply.isPositiveCompletion(reply)) {
ftp.disconnect();
System.err.println("FTP server refused connection.");
System.exit(1);
}
ftp.login(username, password); //设置为被动模式
ftp.enterLocalPassiveMode(); FTPFile[] files = ftp.listFiles("/"); if(files!=null&&files.length>0){ for(FTPFile f:files){ System.out.println("user:>>>"+f.getUser()+" name:>>>"+f.getName()+" size:>>>"+f.getSize()+" link:>>>"+f.getLink()); }
}
} catch (SocketException e) { e.printStackTrace();
} catch (IOException e) { e.printStackTrace();
} }

OK,这样就可以了。

Android 平台下Ftp 使用模拟器需要注意的问题的更多相关文章

  1. [转帖]Android平台下OpenGL初步

    原文请看 Android平台下OpenGL初步 本文只关注于如何一步步实现在Android平台下运用OpenGl. 1.GLSurfaceView GLSurfaceView是Android应用程序中 ...

  2. Android平台下的TCP/IP传输(客户端)

    在工科类项目中,嵌入式系统与软件系统或后台数据库之间的信息传输是实现“物联网”的一种必要的途径,对已简单概念的物联网,通常形式都是一个单片机/嵌入式系统实现数据的采集及其处理,通过蓝牙,wifi或者是 ...

  3. Android平台下Dalvik层hook框架ddi的研究

    通过adbi,可以对native层的所有代码进行hook.但对于Android系统来说,这还远远不够,因为很多应用都还是在Dalvik虚拟机中运行的. 那么,有没有什么办法可以对Dalvik虚拟机中跑 ...

  4. Android平台下OpenCV移植与使用---基于C/C++

    在<Android Studio增加NDK代码编译支持--Mac环境>和<Mac平台下Opencv开发环境搭建>两篇文章中,介绍了如何使用NDK环境和Opencv环境搭建与测试 ...

  5. Android平台下OpenGL初步

    Android OpenGL ES 开发教程 从入门到精通 http://blog.csdn.net/zhoudailiang/article/details/50176143 http://blog ...

  6. Android平台下OpenGL图形编程

    ref: Jayway Team Blog中OpenGL ES简明开发教程https://blog.jayway.com/tag/opengl-es/ OpenGL ES 开发教程http://www ...

  7. Android平台下的JNI开发

    JNI是Java Native Interface的缩写,通过JNI可以方便我们在Android平台上进行C/C++编程.要用JNI首先必须安装Android的NDK,配置好NDK环境之后就可以在Ec ...

  8. 简单探究Android平台下' if ' 语句条件判断耗时情况

    2017年6月13日 前言 前几日在改Bug时看到好多调试时用的日志语句都被一个日志开关控制着它的执行权.形如: if(Constants.LOG_TAG){ Log.d(TAG, "Ini ...

  9. <2014 05 14> Android平台下2D/3D开发攻略

    Android通过OpenGL包含了对高性能2D和3D图形的支持,尤其支持OpenGLES API.OpenGL是一个跨平台的图形API,提供了软件操作3D图形硬件的接口.OpenGLES是一个专用于 ...

随机推荐

  1. [Angular] Intercept HTTP requests in Angular

    Being able to intercept HTTP requests is crucial in a real world application. Whether it is for erro ...

  2. [React Intl] Format Date and Time Using react-intl FormattedDate and FormattedTime

    Using the react-intl FormattedDate and FormattedTime components, we’ll render a JavaScript Date into ...

  3. swift 利用 Reflect(字典转模型)

    1.  导入Reflect(字典转模型)框架 2. 让它继承Reflect这个类,如下代码所示: class IWUser: Reflect { /** *  用户的ID */ var idstr:N ...

  4. 动态规划求解序列问题(LIS、JLIS)

    1. 最长递增子序列 不要求位置连续:要求大小严格递增(strictly increasing) 穷举法解题 首先以每个数字为单位分割寻找最长递增子序列: int lis(const vector&l ...

  5. jQuery笔记---选择器(三)

    1.1查找隐藏的tr元素的个数 $(“table tr:hidden”).size() 查找所有可见的tr元素的个数 $(“table tr:not(:hidden)”).size()   一般是不使 ...

  6. (转)SQL Server 2012笔记分享-25:配置备份维护计划

    本文转自http://543925535.blog.51cto.com/639838/1427529 在日常的SQL维护中,有很多需要重复周期性去做的工作我们不太可能去手动操作完成,比如备份作业.重建 ...

  7. MySQL启动关闭添加到 /etc/init.d/mysqld

      cp /data/mysql/support-files/mysql.server /etc/init.d/mysqld       然后就可以使用此命令启动/关闭 mysql: /etc/ini ...

  8. 8、linux下输入子系统

    input_sync(button_dev);    /*通知接收者,一个报告发送完毕*/ 参考:http://www.51hei.com/bbs/dpj-27652-1.html  很详细说明 in ...

  9. 《Unix编程艺术》读书笔记(1)

    <Unix编程艺术>读书笔记(1) 这两天開始阅读该书,以下是自己的体会,以及原文的摘录,尽管有些东西还无法全然吃透. 写优雅的代码来提高软件系统的透明性:(P134) Elegance ...

  10. [JS Compose] 1. Refactor imperative code to a single composed expression using Box

    After understanding how Box is, then we are going to see how to use Box to refacotr code, to un-nest ...