如何使用java从ftp服务器中删除文件?

问题描述:

如何使用java程序从ftp服务器中删除文件?
我可以使用以下代码成功地在ftp上传文件:

How can I delete a file from an ftp server using a java program? I am successfully able to upload files on the ftp using the following code:

public static void main(String[] args) throws IOException {
    // TODO Auto-generated method stub
    String s = "ftp://username:password@ftpclient:21/text.txt;type=i";
    URL u = new URL(s);
    URLConnection uc = u.openConnection();
    BufferedOutputStream bos = new BufferedOutputStream(uc.getOutputStream());
    bos.write(67);
    bos.close();
    System.out.println("Done");
}

但是如何从这个ftp服务器中删除文件?
任何帮助将不胜感激.........
在此先感谢

But how do i delete files from this ftp server? Any help will be greatly appreciated......... Thanks in advance

您可以使用 Apache FTPClient 来在FTP上执行此操作和所有其他命令。
使用如下所示:

You can use Apache FTPClient to do this and all other commands on FTP. Use it something like this:

...
FTPClient client = new FTPClient();
client.connect(host, port);
client.login(loginname, password);
client.deleteFile(fileNameOnServer);
client.disconnect();
...