simpleFtp 问题
来源:互联网 发布:js点击切换div内容 编辑:程序博客网 时间:2024/06/10 10:23
1、设置连接超时
socket = new Socket();
SocketAddress socketAddress = new InetSocketAddress(host, port);
socket.connect(socketAddress, 5000);
2、获取列表信息
mDataSocket = getConnection();
sendLine("LIST ");
String response = readLine();
// 构造传输文件用的数据流
BufferedInputStream bis = new BufferedInputStream(mDataSocket
.getInputStream());
// 接收来自服务器的数据,写入本地文件
int n;
byte[] buff = new byte[1024];
while ((n = bis.read(buff)) > 0) {
String str = new String(buff,0,n);
Log.d(TAG, ""+ str);
}
private Socket getConnection() throws IOException {
sendLine("PASV");
String response = readLine();
Log.d("FTP", "getConnection response:" + response);
if (response == null || !response.startsWith("227 ")) {
throw new
IOException("SimpleFTP could not request passive mode: "
+ response);
}
String ip = null;
int port = -1;
int opening = response.indexOf('(');
int closing = response.indexOf(')', opening + 1);
if (closing > 0) {
String dataLink = response.substring(opening + 1, closing);
StringTokenizer tokenizer = new StringTokenizer(dataLink, ",");
try {
ip = tokenizer.nextToken() + "." + tokenizer.nextToken() + "."
+ tokenizer.nextToken() + "." + tokenizer.nextToken();
port = Integer.parseInt(tokenizer.nextToken()) * 256
+ Integer.parseInt(tokenizer.nextToken());
} catch (Exception e) {
throw new IOException(
"SimpleFTP received bad data link information: "
+ response);
}
}
Socket dataSocket = new Socket(ip, port);
return dataSocket;
}
- simpleFtp 问题
- simpleFTP
- 问题
- 问题
- 问题
- 问题
- 问题
- 问题
- 问题
- 问题
- 问题
- 问题
- 问题
- 问题
- 问题
- 问题
- 问题
- 问题???
- 私有域的访问权限
- Hibernate使用sql语句查询
- 立德,立功,立言三不朽;为师,为将,为相一完人。写的是谁?
- [转]整理关于java的String 类,equals函数和比较操作符的区别
- 第十三周任务一
- simpleFtp 问题
- C# 获取文件的数字签名信息
- CFormView简介
- HDU 1715 大菲波数
- Windows平台网络游戏服务器端开发
- Hibernate配置文件详解
- Eclipse 3.7 中文字体太小
- C++虚表
- wait() 和waitpid() 函数