本文整理汇总了C#中FtpClient.Close方法的典型用法代码示例。如果您正苦于以下问题:C# FtpClient.Close方法的具体用法?C# FtpClient.Close怎么用?C# FtpClient.Close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FtpClient
的用法示例。
在下文中一共展示了FtpClient.Close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Process
public override ProcessResult Process()
{
ProcessResult res = new ProcessResult();
res.ErrorCode = 0;
Bitmap bmp = null;
Graphics graph = null;
FtpClient ftpClient = null;
try
{
bmp = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, PixelFormat.Format32bppArgb);
graph = Graphics.FromImage(bmp);
graph.CopyFromScreen(Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y, 0, 0, Screen.PrimaryScreen.Bounds.Size, CopyPixelOperation.SourceCopy);
FileName = string.Format("zrzut_{0}-{1}-{2}_{3}.jpg", DateTime.Now.Year.ToString(), DateTime.Now.Month.ToString(), DateTime.Now.Day.ToString(), DateTime.Now.Ticks.ToString());
bmp.Save(FileName, ImageFormat.Jpeg);
ftpClient = new FtpClient(FTPSettings.ServerAddress, FTPSettings.User, FTPSettings.Password);
ftpClient.ChangeDir(FTPSettings.Directory);
ftpClient.Upload(FileName);
System.IO.File.Delete(FileName);
}
catch (Exception exc)
{
res.ErrorCode = 5;
res.ErrorDetails = exc.ToString();
}
finally
{
if (ftpClient != null)
ftpClient.Close();
if (graph != null)
graph.Dispose();
if (bmp != null)
bmp.Dispose();
}
return res;
}
示例2: UploadPicture
/// <summary>
/// TODO - use FtpClient
/// </summary>
/// <param name="imagePath"></param>
private void UploadPicture(string imagePath)
{
string FtpServer = ConfigurationSettings.AppSettings["FtpServer"];
string FtpUserName = ConfigurationSettings.AppSettings["FtpUserName"];
string FtpPassword = ConfigurationSettings.AppSettings["FtpPassword"];
FtpClient ftp = new FtpClient(FtpServer, FtpUserName, FtpPassword);
ftp.Login();
ftp.Upload(imagePath);
ftp.Close();
}
示例3: Write
public static Stream Write(string path)
{
var diskpath = Paths.Map(path);
if (Paths.IsWritable(path)) return new FileStream(diskpath, FileMode.Create, FileAccess.Write);
else if (CanUseFtp) {
var pipe = new PipeStream();
Tasks.Do(() => {
using (pipe)
using (var ftp = new FtpClient()) {
string dir, name;
ftp.Split(path, out dir, out name);
ftp.ChangeDirectory(dir);
ftp.PutFile(pipe, name, Ftp.FileAction.Create);
ftp.Close();
}
});
return pipe;
}
throw new IOException(string.Format("Path {0} is write protected.", path));
}
示例4: Save
public static void Save(Stream src, string path)
{
if (Paths.IsWritable(path)) {
SaveRaw(src, Paths.Map(path));
} else if (CanUseFtp) {
using (var ftp = new FtpClient()) {
string dir, name;
ftp.Split(path, out dir, out name);
ftp.ChangeDirectory(dir);
ftp.PutFile(src, name, Ftp.FileAction.Create);
ftp.Close();
}
} else throw new IOException(string.Format("Path {0} is write protected.", path));
}
示例5: 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));
}
});
}
示例6: CreateDirectory
public static void CreateDirectory(IEnumerable<string> paths)
{
foreach (var path in paths) {
var diskpath = Paths.Map(path);
if (!Directory.Exists(diskpath)) {
if (Paths.IsWritable(path)) Directory.CreateDirectory(diskpath);
else if (CanUseFtp) {
using (var ftp = new FtpClient()) {
string dir, name;
ftp.Split(path, out dir, out name);
if (!dir.IsNullOrEmpty()) ftp.ChangeDirectory(dir);
ftp.MakeDirectory(name);
ftp.Close();
}
} else throw new IOException(string.Format("Path {0} is write protected.", path));
}
}
}
示例7: CopyFileFromFTP
private ProcessResult CopyFileFromFTP()
{
ProcessResult pr = new ProcessResult();
FtpClient ftpClient = null;
pr.ErrorCode = 3;
try
{
ftpClient = new FtpClient(FTPSettings.ServerAddress, FTPSettings.User, FTPSettings.Password);
ftpClient.ChangeDir(FTPSettings.Directory);
ftpClient.Download(RequestedObjectPath, DestinationObjectPath);
pr.ErrorCode = 0;
}
catch (Exception exc)
{
pr.ErrorDetails = exc.ToString();
}
finally
{
try
{
if (ftpClient != null)
{
ftpClient.Close();
}
}
catch { }
}
return pr;
}
示例8: CopyFileToFTP
private ProcessResult CopyFileToFTP()
{
ProcessResult pr = new ProcessResult();
FtpClient ftpClient = null;
pr.ErrorCode = 3;
try
{
if (!File.Exists(RequestedObjectPath))
{
pr.ErrorDetails = "Plik " + RequestedObjectPath + " nie istnieje";
return pr;
}
ftpClient = new FtpClient(FTPSettings.ServerAddress, FTPSettings.User, FTPSettings.Password);
ftpClient.ChangeDir(FTPSettings.Directory);
ftpClient.Upload(RequestedObjectPath);
pr.ErrorCode = 0;
}
catch (Exception exc)
{
pr.ErrorDetails = exc.ToString();
}
finally
{
try
{
if (ftpClient != null)
{
ftpClient.Close();
}
}
catch { }
}
return pr;
}
示例9: UploadFile
public void UploadFile(string filePath)
{
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.PutFile(filePath, FileAction.Create);
}
finally
{
ftp.Close();
}
}
示例10: UploadPackage
public void UploadPackage(string packagePath, string packageVersion)
{
if (!_hasAlreadyFixedStrings)
FixProperties();
_packageFtpClient = new FtpClient();
_packageFtpClient = new FtpClient(Host, Port, Protocol)
{
DataTransferMode = UsePassiveMode ? TransferMode.Passive : TransferMode.Active,
FileTransferType = TransferType.Binary,
Proxy = Proxy != null ? new HttpProxyClient(Proxy.Address.ToString()) : null
};
try
{
_packageFtpClient.TransferProgress += TransferProgressChangedEventHandler;
_packageFtpClient.PutFileAsyncCompleted += UploadPackageFinished;
_packageFtpClient.Open(Username, Password.ConvertToUnsecureString());
_packageFtpClient.ChangeDirectoryMultiPath(Directory);
_packageFtpClient.MakeDirectory(packageVersion);
_packageFtpClient.ChangeDirectory(packageVersion);
_packageFtpClient.PutFileAsync(packagePath, FileAction.Create);
_uploadPackageResetEvent.WaitOne();
}
finally
{
_packageFtpClient.Close();
_uploadPackageResetEvent.Reset();
}
}
示例11: TestConnection
public void TestConnection()
{
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());
}
finally
{
ftp.Close();
}
}
示例12: ListDirectoriesAndFiles
public IEnumerable<FtpItem> ListDirectoriesAndFiles(string path, bool recursive)
{
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());
FtpItemCollection items = recursive ? ftp.GetDirListDeep(path) : ftp.GetDirList(path);
return items;
}
finally
{
ftp.Close();
}
}
示例13: IsExisting
public bool IsExisting(string destinationName)
{
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);
string nameList = null;
try
{
nameList = ftp.GetNameList(destinationName);
}
catch (Exception ex)
{
if (ex.Message.Contains("No such file or directory") || ex.Message.Contains("Directory not found"))
return false;
}
return !string.IsNullOrEmpty(nameList);
}
finally
{
ftp.Close();
}
}
示例14: InternalMoveContent
public void InternalMoveContent(string directory, string aimPath)
{
foreach (FtpItem item in ListDirectoriesAndFiles(directory, false)
.Where(
item => item.FullPath != aimPath && item.FullPath != aimPath.Substring(aimPath.Length - 1)))
{
FtpClient ftp = null;
try
{
ftp = new FtpClient(Host, Port, Protocol)
{
DataTransferMode = UsePassiveMode ? TransferMode.Passive : TransferMode.Active,
FileTransferType = TransferType.Binary,
Proxy = Proxy != null ? new HttpProxyClient(Proxy.Address.ToString()) : null
};
ftp.Open(Username, Password.ConvertToUnsecureString());
Guid guid; // Just for the out-reference of TryParse
if (item.ItemType == FtpItemType.Directory && UpdateVersion.IsValid(item.Name))
{
ftp.ChangeDirectoryMultiPath(aimPath);
if (!IsExisting(aimPath, item.Name))
ftp.MakeDirectory(item.Name);
ftp.ChangeDirectoryMultiPath(item.Name);
InternalMoveContent(item.FullPath, String.Format("{0}/{1}", aimPath, item.Name));
DeleteDirectory(item.FullPath);
}
else if (item.ItemType == FtpItemType.File &&
(item.Name == "updates.json" || Guid.TryParse(item.Name.Split('.')[0], out guid)))
// Second condition determines whether the item is a package-file or not
{
if (!IsExisting(aimPath, item.Name))
{
// "MoveFile"-method damages the files, so we do it manually with a work-around
//ftp.MoveFile(item.FullPath, String.Format("{0}/{1}", aimPath, item.Name));
string localFilePath = Path.Combine(Path.GetTempPath(), item.Name);
ftp.GetFile(item.FullPath, localFilePath, FileAction.Create);
ftp.PutFile(localFilePath, String.Format("{0}/{1}", aimPath, item.Name),
FileAction.Create);
File.Delete(localFilePath);
}
DeleteFile(item.ParentPath, item.Name);
}
}
finally
{
if (ftp != null)
ftp.Close();
}
}
}
示例15: 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();
}
}