本文整理汇总了C#中FtpClient.DeleteFile方法的典型用法代码示例。如果您正苦于以下问题:C# FtpClient.DeleteFile方法的具体用法?C# FtpClient.DeleteFile怎么用?C# FtpClient.DeleteFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FtpClient
的用法示例。
在下文中一共展示了FtpClient.DeleteFile方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DeleteFile
public static void DeleteFile() {
using (FtpClient conn = new FtpClient()) {
conn.Host = "localhost";
conn.Credentials = new NetworkCredential("ftptest", "ftptest");
conn.DeleteFile("/full/or/relative/path/to/file");
}
}
示例2: DeleteFile
public void DeleteFile(string fileName)
{
using (var ftpClient = new FtpClient())
{
ftpClient.Host = _host;
ftpClient.DataConnectionType = FtpDataConnectionType.AutoActive;
ftpClient.Credentials = new NetworkCredential(_username, _password);
ftpClient.Connect();
// ftpClient.CreateDirectory("/test");
ftpClient.SetWorkingDirectory(_folder);
ftpClient.DeleteFile(_folder + ((_folder == "/") ? "" : "/") + fileName);
ftpClient.Disconnect();
}
}
示例3: Delete
public static void Delete(IEnumerable<string> paths)
{
paths.Each(path => {
if (path.Contains("*")) All(path).Each(p => Delete(p));
path = Paths.Normalize(path);
var ftppath = path.Substring(1);
var diskpath = Paths.Map(path);
if (Directory.Exists(diskpath)) {
if (Paths.IsWritable(path)) {
try {
Directory.Delete(diskpath, true);
} catch {
var info = new DirectoryInfo(diskpath);
var children = info.EnumerateFileSystemInfos("*", SearchOption.AllDirectories).ToList();
foreach (var file in children.OfType<FileInfo>()) File.Delete(file.FullName);
children.Reverse();
foreach (var dir in children.OfType<DirectoryInfo>()) Directory.Delete(dir.FullName);
}
} else if (CanUseFtp) {
using (var ftp = new FtpClient()) {
ftp.DeleteDirectoryRecursive(ftppath);
ftp.Close();
}
} else throw new IOException(string.Format("Path {0} is write protected.", path));
} else if (File.Exists(diskpath)) {
if (Paths.IsWritable(path)) File.Delete(diskpath);
else if (CanUseFtp) {
using (var ftp = new FtpClient()) {
string dir, name;
ftp.Split(path, out dir, out name);
ftp.ChangeDirectory(dir);
ftp.DeleteFile(name);
ftp.Close();
}
} else throw new IOException(string.Format("Path {0} is write protected.", path));
}
});
}
示例4: downloadFile
private static void downloadFile(FtpClient client, FtpListItem file, bool deleteFtpFile)
{
string destinationPath = String.Format(@"{0}\{1}", Directory.GetCurrentDirectory(), file.Name);
using (var ftpStream = client.OpenRead(file.FullName)) {
using (var fileStream = File.Create(destinationPath, (int)ftpStream.Length)) {
var buffer = new byte[8 * 1024];
int count;
while ((count = ftpStream.Read(buffer, 0, buffer.Length)) > 0) {
fileStream.Write(buffer, 0, count);
}
}
}
DownloadedFile temp = new DownloadedFile();
temp.originalPath = file.FullName;
temp.fullOriginalPath = client.Host + file.FullName;
temp.finalPath = destinationPath;
temp.name = file.Name;
temp.extension = ".txt";
minervaFiles.Add(temp);
if (deleteFtpFile) {
client.DeleteFile(file.FullName);
}
}
示例5: DeleteFile
public void DeleteFile(string fileName)
{
if (!_hasAlreadyFixedStrings)
FixProperties();
var ftp = new FtpClient(Host, Port, Protocol)
{
DataTransferMode = UsePassiveMode ? TransferMode.Passive : TransferMode.Active,
FileTransferType = TransferType.Binary,
Proxy = Proxy != null ? new HttpProxyClient(Proxy.Address.ToString()) : null
};
try
{
ftp.Open(Username, Password.ConvertToUnsecureString());
ftp.ChangeDirectoryMultiPath(Directory);
ftp.DeleteFile(fileName);
}
finally
{
ftp.Close();
}
}
示例6: ClearFiles
private void ClearFiles(FtpClient ftpClient, string remoteDir) {
if(ftpClient.DirectoryExists(remoteDir) == false)
return;
foreach(var file in Client.ListDirectoryDetail(remoteDir).GetFiles()) {
ftpClient.DeleteFile(file.FullName);
}
}