FTPClient如何删除一个目录? [英] How can FTPClient delete a directory?

查看:1823
本文介绍了FTPClient如何删除一个目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在FTP删除一个文件夹。 FTPClient对象可以删除吗?

I want to Delete a folder in ftp. Can FTPClient object delete it?

推荐答案

的FtpWebRequest提供了删除操作。
下面是一段代码来实现的:

FtpWebRequest provides the Delete action. Here is a piece of code to achieve that :

               FtpWebRequest reqFTP = FtpWebRequest.Create(uri);
                // Credentials and login handling...

                reqFTP.Method = WebRequestMethods.Ftp.DeleteFile;

                string result = string.Empty;
                FtpWebResponse response = reqFTP.GetResponse();
                long size = response.ContentLength;
                Stream datastream = response.GetResponseStream();
                StreamReader sr = new StreamReader(datastream);
                result = sr.ReadToEnd();
                sr.Close();
                datastream.Close();
                response.Close();



应该上的文件和目录。的确,请检查是否有正确的权限。

It should work on files and directories. Indeed, please check that you have the right permissions.

此外,你无法,而他们是不是空删除文件夹。你必须穿过这些递归之前删除的内容。

Also, you could not delete folders while they are not empty. You must traverse them recursively to delete content before.

抛出因右权限问题并不总是很清楚......

The exceptions thrown due to right permissions problems are not always very clear...

这篇关于FTPClient如何删除一个目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆