本文整理汇总了C#中FtpClient.DirectoryExists方法的典型用法代码示例。如果您正苦于以下问题:C# FtpClient.DirectoryExists方法的具体用法?C# FtpClient.DirectoryExists怎么用?C# FtpClient.DirectoryExists使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FtpClient
的用法示例。
在下文中一共展示了FtpClient.DirectoryExists方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DeleteDirectory
public static void DeleteDirectory() {
using (FtpClient conn = new FtpClient()) {
conn.Host = "localhost";
conn.Credentials = new NetworkCredential("ftptest", "ftptest");
if (conn.DirectoryExists("/full/or/relative/path")) {
// do something
}
}
}
示例2: GetNameListing
public static void GetNameListing() {
using (FtpClient cl = new FtpClient()) {
cl.Credentials = new NetworkCredential("ftp", "ftp");
cl.Host = "ftp.example.com";
cl.Connect();
foreach (string s in cl.GetNameListing()) {
// load some information about the object
// returned from the listing...
bool isDirectory = cl.DirectoryExists(s);
DateTime modify = cl.GetModifiedTime(s);
long size = isDirectory ? 0 : cl.GetFileSize(s);
}
}
}
示例3: uploadFTP
/// <summary>
/// Uploads a file to FTP
/// </summary>
/// <param name="localFileName">Local file to upload</param>
/// <param name="uploadPath">URI of the file to upload</param>
/// <param name="silent"></param>
/// <param name="ignoreError"></param>
/// <param name="errorActions"></param>
public static void uploadFTP(string Host, string localFileName, string serverPath, NetworkCredential Credentials, bool silent = false, bool ignoreError = false, string[] errorActions = null)
{
try
{
int bufferSize = 8192;
FtpClient FTP = new FtpClient();
FTP.ValidateCertificate += FTPClient_ValidateCertificate;
FTP.Host = Host;
FTP.Credentials = Credentials;
FTP.Connect();
if (!silent) Logging.logMessage("Connected to: " + Host, 1);
if (!FTP.DirectoryExists(serverPath))
{
Logging.logMessage("Created directory on server: " + serverPath);
FTP.CreateDirectory(serverPath);
}
FileStream localFile = new FileStream(localFileName, FileMode.OpenOrCreate);
byte[] Buffer = new byte[bufferSize];
Stream writeStream = FTP.OpenWrite(serverPath + Path.GetFileName(localFileName), FtpDataType.Binary);
int bytesSent = localFile.Read(Buffer, 0, bufferSize);
while (bytesSent != 0)
{
writeStream.Write(Buffer, 0, bytesSent);
bytesSent = localFile.Read(Buffer, 0, bufferSize);
}
localFile.Close();
writeStream.Close();
FTP.Dispose();
if (!silent) Logging.logMessage("Disconnedted from FTP server", 1);
}
catch (Exception e)
{
if (!ignoreError) Logging.showError("Failed to upload file via FTP:" + Environment.NewLine + e.ToString(), errorActions);
}
}
示例4: createFtpDirectory
private void createFtpDirectory(FtpClient client, string directory) {
try {
if (!client.DirectoryExists(directory) && directory.Length > 1)
client.CreateDirectory(directory);
}
catch (FtpException ftpExc) {
if (ftpExc.Message.Contains("file or directory already exists"))
writeLogEntry(logLevel.Error, string.Format("client.CreateDirectory fehlgeschlagen: {0}", ftpExc.Message));
else
throw;
}
}
示例5: UploadFiles
private void UploadFiles(FtpClient ftpClient, string remoteDir) {
if(!ftpClient.DirectoryExists(remoteDir))
ftpClient.CreateDirectory(remoteDir);
var fis = new FileInfo[FileCount];
for(int i = 0; i < FileCount; i++) {
string file = LocalFileHeader + i;
if(!File.Exists(file))
fis[i] = CreateTestFile(LocalFileHeader + i, BufferSize * 1024 * (i + 1));
else
fis[i] = new FileInfo(file);
}
for(int i = 0; i < FileCount; i++) {
using(new OperationTimer("Upload File:" + fis[i].FullName))
ftpClient.Upload(fis[i], RemoteFileHeader + i).Should().Be.True();
fis[i].Delete();
}
}
示例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);
}
}