功能是想根据FTP服务器上面的指定目录,删除目录下面所有文件,以下是测试代码。
ftpClient.sendServer("DELE README.txt\r\n");
int reply = ftpClient.readServerResponse(); 
if(reply == 250){//success
        System.out.println("File delete success. Filename is README.txt");
}
走到这里正常,reply返回值是250(有点奇怪,弄这么个你懂的数字),到这里单个文件测试正常。接下来想要删除目录下所有文件,也就是需要取目录下列表,也就是说要用到nameList这个函数,不知道还有没有别的,我就知道这个,下面为实际想要的代码。
TelnetInputStream list = ftpClient.nameList(fullPath);ftpClient.sendServer("DELE README.txt\r\n");
int reply = ftpClient.readServerResponse(); 
if(reply == 250){//success
        System.out.println("File delete success. Filename is README.txt");
}
取完列表后再这里进行删除,下面的reply返回值始终是226,这个很奇怪,不管删除文件存在不存在,都是226,这样就午饭判断删除是否成功了。请知道的高手帮帮忙,深表谢意!

解决方案 »

  1.   

    幸运。
    刚问完这个问题,被我自己解决了。ftpClient.cd(remotePath);ftpClient.sendServer("DELE "+ list.get(i) +"\r\n");
    在进行删除前加这么一句,重新指定下路径(奇怪,奇怪,可能是TelnetInputStream list = ftpClient.nameList(fullPath)这里的问题吧,需要重新指定);)
    int reply = ftpClient.readServerResponse(); 
    if(reply == 250){//success
            System.out.println("File delete success. Filename is " + list.get(i));
    }先解决了,有知道详情的请回复,剩下的就接分就好了。
    谢谢关注。
      

  2.   

        FTP reply codes are described in RFC 959.
        Generally, reply code 226 or 250 is used after a successful file transfer, after LIST commands, and after NLST commands.
        Reply code 250 (but not 226) is used for a broader class of FTP commands, such as RNTO, DELE, MKD, RMD, CWD.
        RFC 959 describes the command sequences where a server is allowed to reply with either reply code 226 or reply code 250.可能是没删除成功,所以226,要删除成功的话,就会250