java ftp分片续传_Java写的支持断点续传的FTP

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)

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值