日期:2014-05-20  浏览次数:20644 次

FTP 批量删除服务器文件相关
功能是想根据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,这样就午饭判断删除是否成功了。

请知道的高手帮帮忙,深表谢意!


------解决方案--------------------
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
------解决方案--------------------
好吧 我接分了。
------解决方案--------------------
求代码看看~~~
------解决方案--------------------
一个人唱双簧。。。算是接分。。。