2 mopoking mopoking 于 2014.05.02 22:07 提问

java socket 实现ftp服务器 list命令 返回数据格式

boolean commandLIST()
{
try
{
dsocket = new Socket(remoteHost,remotePort,InetAddress.getLocalHost(),20);
PrintWriter dout = new PrintWriter(dsocket.getOutputStream(),true);
if(param.equals("") || param.equals("LIST"))
{
out.println("150 Opening ASCII mode data connection for /bin/ls. ");
File f = new File(dir);
String[] dirStructure = f.list();
String fileType;
for(int i =0; i<dirStructure.length;i++)
{
if(dirStructure[i].indexOf(".")!=-1)
{
fileType = "- ";
}
else
{
fileType = "d ";
}
out.println(f.listFiles());
}
}
else
{

        }
        dout.close();
        dsocket.close();
        reply = "226 Transfer complete !";
    }
    catch(Exception e)
    {
        e.printStackTrace();
        reply = "451 Requested action aborted: local error in processing";
        return false;
    }

    return false;
}

客户端使用Apache 的 ftpclient listfiles方法,接收后提示
org.apache.commons.net.MalformedServerReplyException: Could not parse response code.
Server Reply: - testb.txt(这是目录下第一个文件名)

怎么解决啊

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!