本文整理汇总了C#中FtpClient.Disconnect方法的典型用法代码示例。如果您正苦于以下问题:C# FtpClient.Disconnect方法的具体用法?C# FtpClient.Disconnect怎么用?C# FtpClient.Disconnect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FtpClient
的用法示例。
在下文中一共展示了FtpClient.Disconnect方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BeginDeleteFile
public static void BeginDeleteFile() {
// 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.BeginDeleteFile("/path/to/file", new AsyncCallback(DeleteFileCallback), conn);
m_reset.WaitOne();
conn.Disconnect();
}
}
示例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: BeginDereferenceLinkExample
public static void BeginDereferenceLinkExample(FtpListItem item) {
// 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.Connect();
if (item.Type == FtpFileSystemObjectType.Link && item.LinkTarget != null) {
conn.BeginDereferenceLink(item, new AsyncCallback(DereferenceLinkCallback), conn);
m_reset.WaitOne();
}
conn.Disconnect();
}
}
示例4: TransferFile
private void TransferFile(string pvtFileName)
{
Event clsEvent = new Event();
try
{
if (!string.IsNullOrEmpty(pvtFileName))
{
if (string.IsNullOrEmpty(mclsAyalaDetails.FTPIPAddress))
{
clsEvent.AddEventLn("Cannot transfer file " + pvtFileName + ". FTP IPAddress is empty Automatic File transfer is disabled.", true);
return;
}
else
clsEvent.AddEventLn("Transferring " + pvtFileName + " to " + mclsAyalaDetails.FTPIPAddress, true);
}
else
{
clsEvent.AddEventLn("Cannot transfer an blank file.", true); return;
}
int intPort = 21;
if (System.Configuration.ConfigurationManager.AppSettings["VersionFTPPort"] != null)
{
try { intPort = int.Parse(System.Configuration.ConfigurationManager.AppSettings["VersionFTPPort"]); }
catch { }
}
FtpClient ftpClient = new FtpClient();
ftpClient.Host = mclsAyalaDetails.FTPIPAddress;
ftpClient.Port = intPort;
ftpClient.Credentials = new NetworkCredential(mclsAyalaDetails.FTPUsername, mclsAyalaDetails.FTPPassword);
IEnumerable<FtpListItem> lstFtpListItem = ftpClient.GetListing(mclsAyalaDetails.FTPDirectory, FtpListOption.Modify | FtpListOption.Size);
bool bolIsFileExist = false;
clsEvent.AddEventLn("Checking file if already exist...", true);
try
{
foreach (FtpListItem ftpListItem in lstFtpListItem)
{
if (ftpListItem.Name.ToUpper() == Path.GetFileName(pvtFileName).ToUpper())
{ bolIsFileExist = true; break; }
}
}
catch (Exception excheck)
{
clsEvent.AddEventLn("checking error..." + excheck.Message, true);
}
if (bolIsFileExist)
{
clsEvent.AddEventLn("exist...", true);
clsEvent.AddEventLn("uploading now...", true);
}
else
{
clsEvent.AddEventLn("does not exist...", true);
clsEvent.AddEventLn("uploading now...", true);
}
using (var fileStream = File.OpenRead(pvtFileName))
using (var ftpStream = ftpClient.OpenWrite(string.Format("{0}/{1}", Path.GetFileName(pvtFileName), Path.GetFileName(pvtFileName))))
{
var buffer = new byte[8 * 1024];
int count;
while ((count = fileStream.Read(buffer, 0, buffer.Length)) > 0)
{
ftpStream.Write(buffer, 0, count);
}
clsEvent.AddEventLn("Upload Complete: TotalBytes: " + buffer.ToString(), true);
}
ftpClient.Disconnect();
ftpClient.Dispose();
ftpClient = null;
clsEvent.AddEventLn("Done.", true);
}
catch (Exception ex)
{
clsEvent.AddEventLn("Error encountered: " + ex.Message, true);
throw new IOException("Sales file is not sent to RLC server. Please contact your POS vendor");
}
}
示例5: ShowRLCServerFileViewer
private void ShowRLCServerFileViewer()
{
ListViewItem lvi;
ListViewItem.ListViewSubItem lvsi;
lstItems.Items.Clear();
int intPort = 21;
if (System.Configuration.ConfigurationManager.AppSettings["VersionFTPPort"] != null)
{
try { intPort = int.Parse(System.Configuration.ConfigurationManager.AppSettings["VersionFTPPort"]); }
catch { }
}
FtpClient ftpClient = new FtpClient();
ftpClient.Host = CONFIG.FTPIPAddress;
ftpClient.Port = intPort;
ftpClient.Credentials = new NetworkCredential(CONFIG.FTPUsername, CONFIG.FTPPassword);
IEnumerable<FtpListItem> lstFtpListItem = ftpClient.GetListing(CONFIG.FTPDirectory, FtpListOption.Modify | FtpListOption.Size);
grpRLC.Text = "RLC File Server Management: [DOUBLE CLICK TO RELOAD] : " + CONFIG.FTPDirectory;
//Int32 iCount = lstFtpListItem.Count();
//Int32 iCtr = 1;
try
{
foreach (FtpListItem ftpListItem in lstFtpListItem)
{
lvi = new ListViewItem();
lvi.Text = ftpListItem.Name;
//lvi.ImageIndex = 0;
lvi.Tag = ftpListItem.FullName;
lvsi = new ListViewItem.ListViewSubItem();
lvsi.Text = ftpListItem.Size.ToString() + " kb";
lvi.SubItems.Add(lvsi);
lvsi = new ListViewItem.ListViewSubItem();
lvsi.Text = ftpListItem.Created.ToString("MM/dd/yyyy hh:mm tt");
lvi.SubItems.Add(lvsi);
lstItems.Items.Add(lvi);
}
}
catch (Exception ex) {
MessageBox.Show("Error encountered while loading file list. " + Environment.NewLine + "Err #: " + ex.Message, "RetailPlus", MessageBoxButtons.OK);
}
ftpClient.Disconnect();
ftpClient.Dispose();
ftpClient = null;
}
示例6: AttachFile
private void AttachFile()
{
try
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.Multiselect = false;
if (ofd.ShowDialog() == DialogResult.OK)
{
string fileName = System.IO.Path.GetFileName(ofd.FileName);
string filePath = System.IO.Path.GetFullPath(ofd.FileName);
string strNewFileName = SalesTransactionItemDetails.TransactionID.ToString() + "_" + SalesTransactionItemDetails.TransactionItemsID + "_" + fileName;
Data.SalesTransactionItemAttachmentDetails clsDetails = new Data.SalesTransactionItemAttachmentDetails();
clsDetails.TransactionItemAttachmentsID = 0;
clsDetails.TransactionItemsID = SalesTransactionItemDetails.TransactionItemsID;
clsDetails.TransactionID = SalesTransactionItemDetails.TransactionID;
clsDetails.OrigFileName = fileName;
clsDetails.FileName = strNewFileName;
clsDetails.UploadedByName = CashierName;
clsDetails.CreatedOn = DateTime.Now;
clsDetails.LastModified = clsDetails.CreatedOn;
Data.SalesTransactionItemAttachments clsSalesTransactionItemAttachments = new Data.SalesTransactionItemAttachments();
clsSalesTransactionItemAttachments.Insert(clsDetails);
clsSalesTransactionItemAttachments.CommitAndDispose();
try
{
string strServer = "127.0.0.1";
if (System.Configuration.ConfigurationManager.AppSettings["VersionFTPIPAddress"] != null)
{
try { strServer = System.Configuration.ConfigurationManager.AppSettings["VersionFTPIPAddress"].ToString(); }
catch { }
}
int intPort = 21;
if (System.Configuration.ConfigurationManager.AppSettings["VersionFTPPort"] != null)
{
try { intPort = int.Parse(System.Configuration.ConfigurationManager.AppSettings["VersionFTPPort"]); }
catch { }
}
string strUserName = "ftprbsuser";
string strPassword = "ftprbspwd";
string strFTPDirectory = "attachment";
string destinationDirectory = Application.StartupPath;
//string strConstantRemarks = "Please contact your system administrator immediately.";
FtpClient ftpClient = new FtpClient();
ftpClient.Host = strServer;
ftpClient.Port = intPort;
ftpClient.Credentials = new NetworkCredential(strUserName, strPassword);
IEnumerable<FtpListItem> lstFtpListItem = ftpClient.GetListing(strFTPDirectory, FtpListOption.Modify | FtpListOption.Size);
Event clsEvent = new Event();
bool bolIsFileExist = false;
clsEvent.AddEventLn("Checking file if already exist...", true);
try
{
foreach (FtpListItem ftpListItem in lstFtpListItem)
{
if (ftpListItem.Name.ToUpper() == Path.GetFileName(strNewFileName).ToUpper())
{ bolIsFileExist = true; break; }
}
}
catch (Exception excheck)
{
clsEvent.AddEventLn("checking error..." + excheck.Message, true);
}
if (bolIsFileExist)
{
clsEvent.AddEventLn("exist...", true);
clsEvent.AddEventLn("uploading now...", true);
}
else
{
clsEvent.AddEventLn("does not exist...", true);
clsEvent.AddEventLn("uploading now...", true);
}
using (var fileStream = File.OpenRead(filePath))
using (var ftpStream = ftpClient.OpenWrite(string.Format("{0}/{1}", strFTPDirectory, Path.GetFileName(strNewFileName))))
{
var buffer = new byte[8 * 1024];
int count;
while ((count = fileStream.Read(buffer, 0, buffer.Length)) > 0)
{
ftpStream.Write(buffer, 0, count);
}
clsEvent.AddEventLn("Upload Complete: TotalBytes: " + buffer.ToString(), true);
}
ftpClient.Disconnect();
//.........这里部分代码省略.........
示例7: UploadFile
public string UploadFile(HttpPostedFileBase file)
{
string destinationFile = _folder + ((_folder == "/") ? "" : "/") + Path.GetFileName(file.FileName);
using (var ftpClient = new FtpClient())
{
ftpClient.Host = _host;
ftpClient.Port = 21;
ftpClient.DataConnectionType = FtpDataConnectionType.EPSV;
ftpClient.Credentials = new NetworkCredential(_username, _password);
ftpClient.Connect();
// ftpClient.CreateDirectory("/test");
ftpClient.SetWorkingDirectory(_folder);
byte[] buf = new byte[8192];
int read = 0;
using (var remoteStream = ftpClient.OpenWrite(destinationFile))
{
using (var localStream = new MemoryStream())
{
// Copy the file data from the posted file into a MemoryStream
file.InputStream.CopyTo(localStream);
// Reset position of stream after copy, otherwise we get zero-length files...
localStream.Position = 0;
while ((read = localStream.Read(buf, 0, buf.Length)) > 0)
{
remoteStream.Write(buf, 0, read);
}
}
}
ftpClient.Disconnect();
return Path.GetFileName(destinationFile);
}
}
示例8: UploadCustomerImage
/// <summary>
/// Uploads the customer image to the FTP site.
/// </summary>
private void UploadCustomerImage()
{
string host = Connection.ApiClient.FtpHost;
if (string.IsNullOrEmpty(host))
{
WriteError(new ErrorRecord(
new NotSupportedException(
"Cannot establish FTP host for non standard API endpoints, use vendor and location parameters to construct a connection."),
"invalid-ftp",
ErrorCategory.InvalidOperation,
host
));
return;
}
var client = new FtpClient
{
Host = host,
EncryptionMode = FtpEncryptionMode.Explicit,
DataConnectionEncryption = true,
Credentials =
Connection.ApiClient.WebApi.Credentials.GetCredential(new Uri(string.Format("ftp://{0}", host)), "Basic")
};
client.Connect();
// TODO : Support for building OVF on the fly.
UploadFile(client, Ovf, 1);
// TODO : Support for building manifest on the fly.
UploadFile(client, Manifest, 2);
UploadFile(client, VirtualImage, 3);
client.Disconnect();
}
示例9: ftpDisconnect
private static void ftpDisconnect(FtpClient client)
{
client.Disconnect();
}