本文整理汇总了C#中FtpClient.DeleteDirectory方法的典型用法代码示例。如果您正苦于以下问题:C# FtpClient.DeleteDirectory方法的具体用法?C# FtpClient.DeleteDirectory怎么用?C# FtpClient.DeleteDirectory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FtpClient
的用法示例。
在下文中一共展示了FtpClient.DeleteDirectory方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DeleteDirectory
public static void DeleteDirectory() {
using (FtpClient conn = new FtpClient()) {
conn.Host = "localhost";
conn.Credentials = new NetworkCredential("ftptest", "ftptest");
// Remove the directory and all objects beneath it. The last parameter
// forces System.Net.FtpClient to use LIST -a for getting a list of objects
// beneath the specified directory.
conn.DeleteDirectory("/path/to/directory", true,
FtpListOption.AllFiles | FtpListOption.ForceList);
}
}
示例2: BeginCreateDirectory
public static void BeginCreateDirectory() {
// The using statement here is OK _only_ because m_reset.WaitOne()
// causes the code to block until the async process finishes, otherwise
// the connection object would be disposed early. In practice, you
// typically would not wrap the following code with a using statement.
using (FtpClient conn = new FtpClient()) {
m_reset.Reset();
conn.Host = "localhost";
conn.Credentials = new NetworkCredential("ftptest", "ftptest");
conn.DeleteDirectory("/test", true);
conn.BeginCreateDirectory("/test/path/that/should/be/created", true,
new AsyncCallback(CreateDirectoryCallback), conn);
m_reset.WaitOne();
conn.Disconnect();
}
}
示例3: DeleteDirectory
public void DeleteDirectory(string directoryPath)
{
if (!_hasAlreadyFixedStrings)
FixProperties();
var ftp = new FtpClient(Host, Port, Protocol);
try
{
IEnumerable<FtpItem> items = ListDirectoriesAndFiles(directoryPath, true);
ftp.DataTransferMode = UsePassiveMode ? TransferMode.Passive : TransferMode.Active;
ftp.FileTransferType = TransferType.Binary;
ftp.Proxy = Proxy != null ? new HttpProxyClient(Proxy.Address.ToString()) : null;
ftp.Open(Username, Password.ConvertToUnsecureString());
foreach (FtpItem item in items)
{
switch (item.ItemType)
{
case FtpItemType.Directory:
DeleteDirectory(String.Format("/{0}/{1}/", directoryPath, item.Name));
break;
case FtpItemType.File:
DeleteFile(directoryPath, item.Name);
break;
}
}
ftp.DeleteDirectory(directoryPath);
}
finally
{
ftp.Close();
}
}