internal FtpMethodInfo(string method, FtpOperation operation, FtpMethodFlags flags, string httpCommand)
 {
     this.Method      = method;
     this.Operation   = operation;
     this.Flags       = flags;
     this.HttpCommand = httpCommand;
 }
 internal FtpMethodInfo(string method, FtpOperation operation, FtpMethodFlags flags, string httpCommand)
 {
     this.Method = method;
     this.Operation = operation;
     this.Flags = flags;
     this.HttpCommand = httpCommand;
 }
        public void DownloadTest()
        {
            FtpOperation cc   = new FtpOperation();
            string       err  = "";
            var          flag = cc.Download(@"E:\\C01317361-gg.CATPart", "ftp://61.161.226.2//MID-FUSELAGE/ENG DATA SET-UPDATED/C01301038-003 --.CATPart", out err);


            Assert.AreEqual(flag, true);
        }
Ejemplo n.º 4
0
 internal FtpMethodInfo(string method,
                        FtpOperation operation,
                        FtpMethodFlags flags,
                        string httpCommand)
 {
     Method = method;
     Operation = operation;
     Flags = flags;
     HttpCommand = httpCommand;
 }
Ejemplo n.º 5
0
        private FtpWebRequest GetFtpWebRequest(string path, FtpOperation method, Settings.FtpSettings settings, bool closeConnection = false)
        {
            if (path.Substring(0, 1) != "/")
            {
                path = $"/{path}";
            }

            FtpWebRequest response = (FtpWebRequest)WebRequest.Create($"ftp://{settings.Host}:{settings.Port}{path}");

            response.Method    = this.ftpClientOperation[method];
            response.UseBinary = true;
            response.KeepAlive = !closeConnection;
            if (settings.Credentials != null)
            {
                response.Credentials = settings.Credentials;
            }

            return(response);
        }
Ejemplo n.º 6
0
        private void button8_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog fbd = new FolderBrowserDialog();

            fbd.SelectedPath = "";// 设置默认路径
            DialogResult ret = fbd.ShowDialog();

            //    string strCollected = string.Empty;


            for (int i = 0; i < checkedListBox1.Items.Count; i++)
            {
                if (checkedListBox1.GetItemChecked(i))
                {
                    string filename = checkedListBox1.GetItemText(checkedListBox1.Items[i]);
                    if (!filename.Contains("ftp"))
                    {
                        string[] tempnamestr = filename.Split('\\');
                        string   shortname   = tempnamestr[tempnamestr.Count() - 1];
                        File.Copy(filename, fbd.SelectedPath + "\\" + shortname, true);
                        // MessageBox.Show("下载完成");
                    }
                    else
                    {
                        string[] tempnamestr = filename.Split('/');
                        string   shortname   = tempnamestr[tempnamestr.Count() - 1];

                        string FileName    = fbd.SelectedPath + "\\" + shortname;
                        string FileNameftp = filename;
                        int    allbye      = this.GetFtpFileSize(FileNameftp);
                        //创建一个文件流
                        FileStream fs             = null;
                        Stream     responseStream = null;
                        try
                        {
                            var saciftp = new FtpOperation();



                            //获取一个请求响应对象
                            FtpWebResponse response = saciftp.Download(filename);

                            //获取请求的响应流
                            responseStream = response.GetResponseStream();

                            //判断本地文件是否存在,如果存在,则打开和重写本地文件

                            if (File.Exists(FileName))
                            {
                                fs = File.Open(FileName, FileMode.Open, FileAccess.ReadWrite);
                            }

                            //判断本地文件是否存在,如果不存在,则创建本地文件
                            else
                            {
                                fs = File.Create(FileName);
                            }

                            if (fs != null)
                            {
                                int    buffer_count = 65536;
                                byte[] buffer       = new byte[buffer_count];
                                int    size         = 0;
                                int    startbye     = 0;

                                progressBar1.Maximum = allbye;
                                progressBar1.Minimum = 0;
                                progressBar1.Visible = true;
                                // this.lbl_ftpStakt.Visible = true;
                                while ((size = responseStream.Read(buffer, 0, buffer_count)) > 0)
                                {
                                    fs.Write(buffer, 0, size);
                                    startbye          += size;
                                    progressBar1.Value = startbye;

                                    label4.Text = "已下载:" + (int)(startbye / 1024) + "KB/" + "总长度:" + (int)(allbye / 1024) + "KB" + " " + " 文件名:" + FileNameftp;
                                    System.Windows.Forms.Application.DoEvents();
                                }
                                fs.Flush();
                                fs.Close();
                                responseStream.Close();
                            }
                        }
                        finally
                        {
                            if (fs != null)
                            {
                                fs.Close();
                            }
                            if (responseStream != null)
                            {
                                responseStream.Close();
                            }
                        }
                    }
                }
            }
            MessageBox.Show("下载已完成,保存在:" + fbd.SelectedPath);
        }
Ejemplo n.º 7
0
 private bool TryInvokeFtpOperation(Func<FtpException, Boolean> exceptionAccepted, FtpOperation opType, Func<bool> operation)
 {
     try
       {
     return InvokeFtpOperation(opType, operation);
       }
       catch (FtpException e)
       {
     if (exceptionAccepted(e))
     {
       return false;
     }
     throw;
       }
 }
Ejemplo n.º 8
0
 private bool InvokeFtpOperation(FtpOperation opType, Func<bool> operation)
 {
     lock (mLock)
       {
     try
     {
       Op = opType;
       try
       {
     return operation.Invoke();
       }
       catch (Exception e)
       {
     FtpException decoded;
     if (DecodeException(e, out decoded))
     {
       throw decoded;
     }
     throw;
       }
     }
     finally
     {
       Op = FtpOperation.None;
     }
       }
 }