ZCH1991926 2014-05-02 14:07 采纳率: 0%
浏览 1968

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(这是目录下第一个文件名)

怎么解决啊

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 vc6.0中想运行代码的时候总是提示无法打开文件是怎么回事
    • ¥25 关于##爬虫##的问题,如何解决?:
    • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
    • ¥15 找一位技术过硬的游戏pj程序员
    • ¥15 matlab生成电测深三层曲线模型代码
    • ¥50 随机森林与房贷信用风险模型
    • ¥50 buildozer打包kivy app失败
    • ¥30 在vs2022里运行python代码
    • ¥15 不同尺寸货物如何寻找合适的包装箱型谱
    • ¥15 求解 yolo算法问题