public void testFtp(){
FtpClient ftp=null;
try {
ftp = new FtpClient();
ftp.openServer("192.168.4.63");//打开会话
ftp.login("root", "xwtech");//登录
//ftp.cd("/test");//改变ftp当前目录
//当前目录路径+/test/test2.txt,获得指定ftp上的文件
TelnetInputStream tel=ftp.get("/test/test2.txt");
//由inputStream流变成inputStreamReader流
InputStreamReader inputStreamReader=new InputStreamReader(tel);
//由reader流变成BufferedReader流
BufferedReader bufferedReader=new BufferedReader(inputStreamReader);
String content=null;
//读取一行,如果为空,则流已到最后
while((content=bufferedReader.readLine())!=null){
System.out.println(content);
}
bufferedReader.close();
inputStreamReader.close();
tel.close();
} catch (IOException e) {
e.printStackTrace();
}finally{
if(ftp!=null){
try {
ftp.closeServer();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}