织梦CMS - 轻松建站从此开始!

罗索

当前位置: 主页>杂项技术>JAVA>

Java写的支持断点续传的FTP

罗索客 发布于 2002-07-24 14:46 点击:次 
Java写的支持断点续传的FTP 很不错的值得研究一下,结构比较清楚。 基类一: package ming.ftpsearch; public class FileInfo { public String name; public String description; public FileInfo(String nm,String dscrp) { name=nm; description=dscrp; } } 基类二:
TAG:

Java写的支持断点续传的FTP
很不错的值得研究一下,结构比较清楚。

基类一:  

package ming.ftpsearch;  



public class FileInfo  

{  

public String name;  

public String description;  

public FileInfo(String nm,String dscrp)  

{  

name=nm;  

description=dscrp;  

}  

}  





基类二:  

package ming.ftpsearch;  



import java.io.*;  

import java.net.*;  

import java.util.*;  





public class FTPSearch extends Thread  

{  

String _host;  

static final int PORT=21;  

ServerSocket ss;  

Socket _ds;  

Socket _sc;  

PrintStream _out ;  

String _hostAddress;  

BufferedReader _in ;  

BufferedReader _dataIn;  

String _reply;  

protected StringBuffer _log=new StringBuffer(10000);  

Vector _result;  

String _user;  

String _pass;  



public FTPSearch (String ip,String user,String pass)  

{  

_host=ip;  

_user=user;  

_pass=pass;  

_result=new Vector();  

}  





public FTPSearch (String ip)  

{  

_host=ip;  

_user="anonymous";  

_pass="name_zm@sohu.com";  

_result=new Vector();  

}  



protected boolean login()throws UnknownHostException,IOException  

{  

boolean successful=false;  

StringBuffer reply=new StringBuffer();  

_sc=new Socket(_host,PORT);  

_hostAddress=_sc.getLocalAddress().getHostAddress().replace(''.'','','');  

_sc.setSoTimeout(15000);  

_out = new PrintStream(_sc.getOutputStream(),true);  

_in = new BufferedReader(new InputStreamReader(_sc.getInputStream()));  

reply.append(readReply().trim());  

if(reply.toString().startsWith("220"))  

if(comm("USER "+_user))  

if(comm("PASS "+_pass))  

successful=true;  

comm("TYPE A");  

return successful;  

}  





protected String getCurrentDir()throws IOException  

{  

String currentDir=null;  

if(comm("PWD"))  

{  

StringTokenizer st=new StringTokenizer(_reply);  

st.nextToken();  

StringBuffer rtDir=new StringBuffer(st.nextToken());  

currentDir=rtDir.substring(1,rtDir.length()-1);  

}  

return currentDir;  

}  



public void search()throws IOException,InterruptedException  

{  

try  

{  

for(int i=0;i<5;i++)  

{  

if(login())break;  

System.out.println("Wait 10 seconds to try again...");  

sleep(10000);  

}  

scan();  

logout();  

}  

catch(IOException ex)  

{  



}  

finally  

{  

PrintStream out=new PrintStream(new FileOutputStream("Log.txt"));  

out.println(_log);  

out.close();  

printResult("result.txt");  

}
} (iwgh)
本站文章除注明转载外,均为本站原创或编译欢迎任何形式的转载,但请务必注明出处,尊重他人劳动,同学习共成长。转载请注明:文章转载自:罗索实验室 [http://www.rosoo.net/a/200207/1279.html]
本文出处: 作者:iwgh
顶一下
(0)
0%
踩一下
(6)
100%
------分隔线----------------------------
发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
评价:
表情:
用户名: 验证码:点击我更换图片
栏目列表
将本文分享到微信
织梦二维码生成器
推荐内容