当前位置: 首页>>代码示例>>C#>>正文


C# FtpClient.Dispose方法代码示例

本文整理汇总了C#中FtpClient.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# FtpClient.Dispose方法的具体用法?C# FtpClient.Dispose怎么用?C# FtpClient.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在FtpClient的用法示例。


在下文中一共展示了FtpClient.Dispose方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: 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");
            }
        }
开发者ID:marioricci,项目名称:erp-luma,代码行数:84,代码来源:Ayala.cs

示例2: 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();
//.........这里部分代码省略.........
开发者ID:marioricci,项目名称:erp-luma,代码行数:101,代码来源:ItemAttachmentWnd.cs

示例3: 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;
        }
开发者ID:marioricci,项目名称:erp-luma,代码行数:52,代码来源:ForwarderWnd.cs

示例4: 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);
            }

        }
开发者ID:RX14,项目名称:RX-UTILS.NET,代码行数:51,代码来源:Web.cs


注:本文中的FtpClient.Dispose方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。