如何使用java从ftp服务器中删除文件? [英] how to delete file from ftp server using java?
本文介绍了如何使用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();
...
这篇关于如何使用java从ftp服务器中删除文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文