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


C# FtpClient.GetListing方法代码示例

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


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

示例1: DereferenceLinkExample

        /// <summary>
        /// Example illustrating how to dereference a symbolic link
        /// in a file listing. You can also pass the FtpListOption.DerefLinks
        /// flag to GetListing() to have automatically done in which
        /// case the FtpListItem.LinkObject property will contain the
        /// FtpListItem representing the object the link points at. The
        /// LinkObject property will be null if there was a problem resolving
        /// the target.
        /// </summary>
        public static void DereferenceLinkExample() {
            using (FtpClient client = new FtpClient()) {
                client.Credentials = new NetworkCredential("user", "pass");
                client.Host = "somehost";

                // This propety controls the depth of recursion that
                // can be done before giving up on resolving the link.
                // You can set the value to -1 for infinite depth 
                // however you are strongly discourage from doing so.
                // The default value is 20, the following line is
                // only to illustrate the existance of the property.
                // It's also possible to override this value as one
                // of the overloaded arguments to the DereferenceLink() method.
                client.MaximumDereferenceCount = 20;

                // Notice the FtpListOption.ForceList flag being passed. This is because
                // symbolic links are only supported in UNIX style listings. My personal
                // experience has been that in practice MLSD listings don't specify an object
                // as a link, but rather list the link as a regular file or directory
                // accordingly. This may not always be the case however that's what I've
                // observed over the life of this project so if you run across the contrary
                // please report it. The specification for MLSD does include links so it's
                // possible some FTP server implementations do include links in the MLSD listing.
                foreach (FtpListItem item in client.GetListing(null, FtpListOption.ForceList | FtpListOption.Modify)) {
                    Console.WriteLine(item);

                    // If you call DerefenceLink() on a FtpListItem.Type other
                    // than Link a FtpException will be thrown. If you call the
                    // method and the LinkTarget is null a FtpException will also
                    // be thrown.
                    if (item.Type == FtpFileSystemObjectType.Link && item.LinkTarget != null) {
                        item.LinkObject = client.DereferenceLink(item);

                        // The return value of DerefenceLink() will be null
                        // if there was a problem.
                        if (item.LinkObject != null) {
                            Console.WriteLine(item.LinkObject);
                        }
                    }
                }

                // This example is similar except it uses the FtpListOption.DerefLinks
                // flag to have symbolic links automatically resolved. You must manually
                // specify this flag because of the added overhead with regards to resolving
                // the target of a link.
                foreach (FtpListItem item in client.GetListing(null,
                    FtpListOption.ForceList | FtpListOption.Modify | FtpListOption.DerefLinks)) {

                    Console.WriteLine(item);

                    if (item.Type == FtpFileSystemObjectType.Link && item.LinkObject != null) {
                        Console.WriteLine(item.LinkObject);
                    }
                }
            }
        }
开发者ID:fanpan26,项目名称:Macrosage.Wx,代码行数:65,代码来源:DereferenceLink.cs

示例2: GetListing

        public static void GetListing() {
            using (FtpClient conn = new FtpClient()) {
                conn.Host = "localhost";
                conn.Credentials = new NetworkCredential("ftptest", "ftptest");
                
                foreach (FtpListItem item in conn.GetListing(conn.GetWorkingDirectory(),
                    FtpListOption.Modify | FtpListOption.Size)) {

                    switch (item.Type) {
                        case FtpFileSystemObjectType.Directory:
                            break;
                        case FtpFileSystemObjectType.File:
                            break;
                        case FtpFileSystemObjectType.Link:
                            // derefernece symbolic links
                            if (item.LinkTarget != null) {
                                // see the DereferenceLink() example
                                // for more details about resolving links.
                                item.LinkObject = conn.DereferenceLink(item);

                                if (item.LinkObject != null) {
                                    // switch (item.LinkObject.Type)...
                                }
                            }
                            break;
                    }
                }

                // same example except automatically dereference symbolic links.
                // see the DereferenceLink() example for more details about resolving links.
                foreach (FtpListItem item in conn.GetListing(conn.GetWorkingDirectory(),
                    FtpListOption.Modify | FtpListOption.Size | FtpListOption.DerefLinks)) {

                    switch (item.Type) {
                        case FtpFileSystemObjectType.Directory:
                            break;
                        case FtpFileSystemObjectType.File:
                            break;
                        case FtpFileSystemObjectType.Link:
                            if (item.LinkObject != null) {
                                // switch (item.LinkObject.Type)...
                            }
                            break;
                    }
                }
            }
        }
开发者ID:Kylia669,项目名称:DiplomWork,代码行数:47,代码来源:GetListing.cs

示例3: TestIssue3

 public void TestIssue3()
 {
     var ftpClient = new FtpClient("anonymous",
                                   string.Empty,
                                   "ftp://ftp.mozilla.org");
     var ftpListItems = ftpClient.GetListing("/");
     Assert.IsNotNull(ftpListItems);
     Assert.IsTrue(ftpListItems.Any());
 }
开发者ID:dittodhole,项目名称:dotnet-silverlight-ftp,代码行数:9,代码来源:FtpClientTest.cs

示例4: VerifyListing

        public void VerifyListing(string host, string username, string password)
        {
            var ftpClient = new FtpClient();

            ftpClient.Host = host;
            ftpClient.Credentials = new NetworkCredential(username, password);
            ftpClient.Connect();
            var listing = ftpClient.GetListing();
            Assert.IsNotNull(listing);
        }
开发者ID:talanc,项目名称:FtpServerTest,代码行数:10,代码来源:FtpTests.cs

示例5: TestWorkFlow

        public void TestWorkFlow()
        {
            var config = SetupBootstrap("Basic.config");

            using(var client = new FtpClient())
            {
                client.Host = "localhost";
                client.InternetProtocolVersions = FtpIpVersion.IPv4;
                client.Credentials = new NetworkCredential("kerry", "123456");
                client.DataConnectionType = FtpDataConnectionType.PASV;
                client.Connect();
                Assert.AreEqual(true, client.IsConnected);
                var workDir = client.GetWorkingDirectory();
                Assert.AreEqual("/", workDir);
                Console.WriteLine("EncryptionMode: {0}", client.EncryptionMode);
                foreach (var item in client.GetListing(workDir, FtpListOption.Size))
                {
                    Console.WriteLine(item.Name);
                }
            }
        }
开发者ID:jmptrader,项目名称:SuperSocket.FtpServer,代码行数:21,代码来源:BasicTest.cs

示例6: 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

示例7: 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

示例8: OpenAttachment

        private void OpenAttachment()
        {
            try
            {
                string strTempPath = Application.StartupPath + "/temp/";
                string strFile = "";

                if (dgvItems.SelectedRows.Count == 1)
                {
                    if (!Directory.Exists(strTempPath)) Directory.CreateDirectory(strTempPath);

                    foreach (DataGridViewRow dr in dgvItems.SelectedRows)
                    {
                        strFile = strTempPath + dr.Cells["FileName"].Value.ToString();

                        if (System.IO.File.Exists(strFile))
                        try { System.IO.File.Delete(strFile); }
                        catch { }

                        #region Download

                        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";

                            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)
                            //        .Where(ftpListItem => string.Equals(Path.GetExtension(ftpListItem.Name), ".dll"));

                            IEnumerable<FtpListItem> lstFtpListItem = ftpClient.GetListing(strFTPDirectory, FtpListOption.Modify | FtpListOption.Size);

                            Int32 iCount = lstFtpListItem.Count();
                            Int32 iCtr = 1;

                            // List all files with a .txt extension
                            foreach (FtpListItem ftpListItem in lstFtpListItem)
                            {
                                if (ftpListItem.Name.ToLower() == dr.Cells["FileName"].Value.ToString().ToLower())
                                {
                                    // Report progress as a percentage of the total task. 
                                    decimal x = ((decimal.Parse(iCtr.ToString()) / decimal.Parse(iCount.ToString()) * decimal.Parse("100")) - decimal.Parse("1"));
                                    iCtr++;

                                    strFile = string.Format(@"{0}{1}", strTempPath, ftpListItem.Name);

                                    using (var ftpStream = ftpClient.OpenRead(ftpListItem.FullName))
                                    using (var fileStream = File.Create(strFile, (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);
                                        }
                                    }

                                    //System.Diagnostics.Process.Start(strFile);

                                    try
                                    { Common.OpenFileToDOS(strFile); }
                                    catch (Exception ex)
                                    {
                                        MessageBox.Show("Error opening file. You may directly open the file @: " + strFile + Environment.NewLine + "Error details: " + ex.InnerException.Message, "RetailPlus", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                    }
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show("Error opening file, the system cannot connect to FTP server. Please consult your System Administrator." + Environment.NewLine + "Error details: " + ex.InnerException.Message, "RetailPlus", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }

                        #endregion
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "RetailPlus", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
//.........这里部分代码省略.........
开发者ID:marioricci,项目名称:erp-luma,代码行数:101,代码来源:ItemAttachmentWnd.cs

示例9: 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

示例10: getSubGroupImages

        private static bool getSubGroupImages()
        {
            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 = "subgroupimages";

                string destinationDirectory = Application.StartupPath + @"\images\subgroups";

                FtpClient ftpClient = new FtpClient();
                ftpClient.Host = strServer;
                ftpClient.Port = intPort;
                ftpClient.Credentials = new NetworkCredential(strUserName, strPassword);

                System.Collections.Generic.IEnumerable<FtpListItem> lstFtpListItem = ftpClient.GetListing(strFTPDirectory, FtpListOption.Modify | FtpListOption.Size);

                // List all files with a .txt extension
                foreach (FtpListItem ftpListItem in lstFtpListItem)
                {
                    var destinationPath = string.Format(@"{0}\{1}", destinationDirectory, ftpListItem.Name);

                    using (var ftpStream = ftpClient.OpenRead(ftpListItem.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);
                        }
                    }
                }
            }
            catch
            { }
            return true;
        }
开发者ID:marioricci,项目名称:erp-luma,代码行数:52,代码来源:Program.cs

示例11: GetLatestVersion

        private static Version GetLatestVersion()
        {
            Version clsVersion = new Version("0.0.0.0");
            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";
                if (System.Configuration.ConfigurationManager.AppSettings["VersionFTPUserName"] != null)
                {
                    try { strUserName = System.Configuration.ConfigurationManager.AppSettings["VersionFTPUserName"].ToString(); }
                    catch { }
                }

                string strPassword = "ftprbspwd";
                if (System.Configuration.ConfigurationManager.AppSettings["VersionFTPPassword"] != null)
                {
                    try { strPassword = System.Configuration.ConfigurationManager.AppSettings["VersionFTPPassword"].ToString(); }
                    catch { }
                }

                string strFTPDirectory = "RetailPlusClient";
                if (System.Configuration.ConfigurationManager.AppSettings["VersionFTPDirectory"] != null)
                {
                    try { strFTPDirectory = System.Configuration.ConfigurationManager.AppSettings["VersionFTPDirectory"].ToString(); }
                    catch { }
                }

                string strXMLFile = Application.StartupPath + "\\version.xml";
                string destinationDirectory = Application.StartupPath;

                FtpClient ftpClient = new FtpClient();
                ftpClient.Host = strServer;
                ftpClient.Port = intPort;
                ftpClient.Credentials = new NetworkCredential(strUserName, strPassword);

                System.Collections.Generic.IEnumerable<FtpListItem> lstFtpListItem = ftpClient.GetListing(strFTPDirectory, FtpListOption.Modify | FtpListOption.Size);

                // List all files with a .txt extension
                foreach (FtpListItem ftpListItem in lstFtpListItem)
                {
                    if (ftpListItem.Name.ToLower() == "version.xml" ||
                        ftpListItem.Name.ToLower() == "retailplus.versionchecker.exe" ||
                        ftpListItem.Name.ToLower() == "retailplus.versionchecker.exe.config")
                    {

                        var destinationPath = string.Format(@"{0}\{1}", destinationDirectory, ftpListItem.Name);

                        using (var ftpStream = ftpClient.OpenRead(ftpListItem.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);
                            }
                        }
                    }
                }

                string strVersion = string.Empty;
                #region Assign the Version from XML File to strVersion
                XmlReader xmlReader = new XmlTextReader(strXMLFile);
                xmlReader.MoveToContent();
                string strElementName = string.Empty;

                if ((xmlReader.NodeType == XmlNodeType.Element) && (xmlReader.Name == "RetailPlus"))
                {
                    while (xmlReader.Read())
                    {
                        // we remember its name  
                        if (xmlReader.NodeType == XmlNodeType.Element)
                            strElementName = xmlReader.Name;
                        else
                        {
                            // for text nodes...  
                            if ((xmlReader.NodeType == XmlNodeType.Text) && (xmlReader.HasValue))
                            {
                                // we check what the name of the node was  
                                switch (strElementName)
                                {
                                    case "version":
                                        strVersion = xmlReader.Value;
                                        break;
                                }
                            }
                        }
//.........这里部分代码省略.........
开发者ID:marioricci,项目名称:erp-luma,代码行数:101,代码来源:Program.cs

示例12: GetListFiles

        public List<FtpFile> GetListFiles()
        {
            List<FtpFile> listFtpFiles = new List<FtpFile>();

            StringBuilder requestUri = new StringBuilder();
            if (string.IsNullOrEmpty(this.Path))
            {
                requestUri.Append("/");
            }
            else
            {
                if (!this.Password.StartsWith("/"))
                {
                    requestUri.Append("/");
                }
                requestUri.Append(Path);
                if (!Path.EndsWith("/"))
                {
                    requestUri.Append("'/");
                }
            }

            FtpClient ftpClient = new FtpClient(UserName, Password, HostName);

            FtpListItem[] listItems = ftpClient.GetListing(requestUri.ToString());
            foreach (FtpListItem item in listItems)
            {
                FtpFile ftpFile = new FtpFile()
                {
                    FileType = item.Type.ToString(),
                    Name = item.Name,
                    LastWriteTime = item.Modify
                };
                listFtpFiles.Add(ftpFile);
            }
            return listFtpFiles;
        }
开发者ID:haizhixing126,项目名称:PYSConsole,代码行数:37,代码来源:FtpServer.cs

示例13: backgroundWorker1_DoWork

        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            // Get the BackgroundWorker that raised this event.
            BackgroundWorker worker = sender as BackgroundWorker;

            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 = "retailplusclient";

                string destinationDirectory = Application.StartupPath;
                //string strConstantRemarks = "Please contact your system administrator immediately.";

                mstStatus = "getting ftp server configuration...";
                worker.ReportProgress(1);

                FtpClient ftpClient = new FtpClient();
                ftpClient.Host = strServer;
                ftpClient.Port = intPort;
                ftpClient.Credentials = new NetworkCredential(strUserName, strPassword);

                mstStatus = "connecting to ftp server " + strServer + "...";
                worker.ReportProgress(2);

                //IEnumerable<FtpListItem> lstFtpListItem = ftpClient.GetListing(strFTPDirectory, FtpListOption.Modify | FtpListOption.Size)
                //        .Where(ftpListItem => string.Equals(Path.GetExtension(ftpListItem.Name), ".dll"));

                IEnumerable<FtpListItem> lstFtpListItem = ftpClient.GetListing(strFTPDirectory, FtpListOption.Modify | FtpListOption.Size);

                mstStatus = "connecting to ftp server " + strServer + "... done.";
                worker.ReportProgress(5);
                System.Threading.Thread.Sleep(10);

                Int32 iCount =  lstFtpListItem.Count();
                Int32 iCtr = 1;

                mstStatus = "copying " + iCount.ToString() + " files from retailplusclient...";
                worker.ReportProgress(10);
                System.Threading.Thread.Sleep(10);

                // List all files with a .txt extension
                foreach (FtpListItem ftpListItem in lstFtpListItem)
                {
                    if (ftpListItem.Name.ToLower() != "version.xml" &&
                        ftpListItem.Name.ToLower() != "retailplus.versionchecker.exe" &
                        ftpListItem.Name.ToLower() != "retailplus.versionchecker.exe.config")
                    {
                        // Report progress as a percentage of the total task. 
                        mstStatus = "copying file: " + ftpListItem.Name + " ...";
                        decimal x = ((decimal.Parse(iCtr.ToString()) / decimal.Parse(iCount.ToString()) * decimal.Parse("100")) - decimal.Parse("1"));
                        iCtr++;

                        Int32 iProgress = Int32.Parse(Math.Round(x, 0).ToString());
                        worker.ReportProgress(iProgress >= 90 ? 90 : iProgress);

                        var destinationPath = string.Format(@"{0}\{1}", destinationDirectory, ftpListItem.Name);

                        using (var ftpStream = ftpClient.OpenRead(ftpListItem.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);
                            }
                        }
                    }
                }

                mstStatus = "Done copying all files...";

                worker.ReportProgress(100);
                System.Threading.Thread.Sleep(100);
                System.Diagnostics.Process.Start(ExecutableSender);
                Application.Exit();
            }
            catch { }
        }
开发者ID:marioricci,项目名称:erp-luma,代码行数:94,代码来源:MainWnd.cs


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