Пример #1
0
            public FTPDownloadClient(FTPClientManager manager)
            {
                if (manager == null)
                {
                    throw new ArgumentNullException("FTPClientManager cannot be null.");
                }

                this.manager = manager;
            }
Пример #2
0
            public FTPDownloadClient(FTPClientManager manager)
            {
                if (manager == null)
                {
                    throw new ArgumentNullException("FTPClientManager cannot be null.");
                }

                this.manager = manager;
            }
Пример #3
0
        void Connect(string urlStr)
        {
            try
            {
                Uri url = new Uri(urlStr);

                // The schema of url must be ftp.
                if (!url.Scheme.Equals("ftp", StringComparison.OrdinalIgnoreCase))
                {
                    throw new ApplicationException("The schema of url must be ftp. ");
                }

                // Set the url to the folder that contains this file.
                if (url.IsFile)
                {
                    url = new Uri(url, "..");
                }

                // Show the Form UICredentialsProvider to get new Credentials.
                using (UICredentialsProvider provider =
                           new UICredentialsProvider(this.currentCredentials))
                {
                    // Show the Form UICredentialsProvider as a dialog.
                    var result = provider.ShowDialog();

                    // If user typed the Credentials and pressed the "OK" button.
                    if (result == System.Windows.Forms.DialogResult.OK)
                    {
                        // Reset the current Credentials.
                        this.currentCredentials = provider.Credentials;
                    }
                    else
                    {
                        return;
                    }
                }

                // Initialize the FTPClient instance.
                client = new FTPClientManager(url, currentCredentials);

                client.UrlChanged            += new EventHandler(client_UrlChanged);
                client.StatusChanged         += new EventHandler(client_StatusChanged);
                client.ErrorOccurred         += new EventHandler <ErrorEventArgs>(client_ErrorOccurred);
                client.FileDownloadCompleted +=
                    new EventHandler <FileDownloadCompletedEventArgs>(client_FileDownloadCompleted);
                client.NewMessageArrived +=
                    new EventHandler <NewMessageEventArg>(client_NewMessageArrived);

                // List the sub directories and files.
                RefreshSubDirectoriesAndFiles();
            }


            catch (System.Net.WebException webEx)
            {
                if ((webEx.Response as FtpWebResponse).StatusCode == FtpStatusCode.NotLoggedIn)
                {
                    // Reconnect the server.
                    Connect(urlStr);

                    return;
                }
                else
                {
                    MessageBox.Show(webEx.Message);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Пример #4
0
        void Connect(string urlStr)
        {
            try
            {
                Uri url = new Uri(urlStr);

                // URL的模式必须是FTP的.
                if (!url.Scheme.Equals("ftp", StringComparison.OrdinalIgnoreCase))
                {
                    throw new ApplicationException("URL的模式必须是FTP的. ");
                }


                // 把这个url转到这个文件夹并且这个文件夹包括这个文件。
                if (url.IsFile)
                {
                    url = new Uri(url, "..");
                }



                //显示窗体UICredentialsProvider获得新的凭据.
                using (UICredentialsProvider provider =
                           new UICredentialsProvider(this.currentCredentials))
                {
                    // 显示UICredentialsProvider作为一个对话框.
                    var result = provider.ShowDialog();

                    // 如果用户输入了凭据并且按下了 "确定" 按钮.
                    if (result == System.Windows.Forms.DialogResult.OK)
                    {
                        //重置当前的凭据.
                        this.currentCredentials = provider.Credentials;
                    }
                    else
                    {
                        return;
                    }
                }

                // 初始化FTPClient实例.
                client = new FTPClientManager(url, currentCredentials);

                client.UrlChanged            += new EventHandler(client_UrlChanged);
                client.StatusChanged         += new EventHandler(client_StatusChanged);
                client.ErrorOccurred         += new EventHandler <ErrorEventArgs>(client_ErrorOccurred);
                client.FileDownloadCompleted +=
                    new EventHandler <FileDownloadCompletedEventArgs>(client_FileDownloadCompleted);
                client.NewMessageArrived +=
                    new EventHandler <NewMessageEventArg>(client_NewMessageArrived);

                // 子目录和文件的列表.
                RefreshSubDirectoriesAndFiles();
            }


            catch (System.Net.WebException webEx)
            {
                if ((webEx.Response as FtpWebResponse).StatusCode == FtpStatusCode.NotLoggedIn)
                {
                    //重新连接服务器。
                    Connect(urlStr);

                    return;
                }
                else
                {
                    MessageBox.Show(webEx.Message);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Пример #5
0
        void Connect(string urlStr)
        {
            try
            {
                Uri url = new Uri(urlStr);

                // URL的模式必须是FTP的.
                if (!url.Scheme.Equals("ftp", StringComparison.OrdinalIgnoreCase))
                {
                    throw new ApplicationException("URL的模式必须是FTP的. ");
                }

                // 把这个url转到这个文件夹并且这个文件夹包括这个文件。
                if (url.IsFile)
                {
                    url = new Uri(url, "..");
                }

                //显示窗体UICredentialsProvider获得新的凭据.
                using (UICredentialsProvider provider =
                    new UICredentialsProvider(this.currentCredentials))
                {

                    // 显示UICredentialsProvider作为一个对话框.
                    var result = provider.ShowDialog();

                    // 如果用户输入了凭据并且按下了 "确定" 按钮.
                    if (result == System.Windows.Forms.DialogResult.OK)
                    {

                        //重置当前的凭据.
                        this.currentCredentials = provider.Credentials;

                    }
                    else
                    {
                        return;
                    }
                }

                // 初始化FTPClient实例.
                client = new FTPClientManager(url, currentCredentials);

                client.UrlChanged += new EventHandler(client_UrlChanged);
                client.StatusChanged += new EventHandler(client_StatusChanged);
                client.ErrorOccurred += new EventHandler<ErrorEventArgs>(client_ErrorOccurred);
                client.FileDownloadCompleted +=
                    new EventHandler<FileDownloadCompletedEventArgs>(client_FileDownloadCompleted);
                client.NewMessageArrived +=
                    new EventHandler<NewMessageEventArg>(client_NewMessageArrived);

                // 子目录和文件的列表.
                RefreshSubDirectoriesAndFiles();
            }

            catch (System.Net.WebException webEx)
            {
                if ((webEx.Response as FtpWebResponse).StatusCode == FtpStatusCode.NotLoggedIn)
                {
                    //重新连接服务器。
                    Connect(urlStr);

                    return;
                }
                else
                {
                    MessageBox.Show(webEx.Message);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }