예제 #1
0
        private void btn_download_Click(object sender, EventArgs e)
        {
            #region  载
            if (listBox1.SelectedItem == null)
            {
                MsgBox.ShowInfoMsg("请选择下载的文档!");
            }
            else
            {
                SaveFileDialog dlg = new SaveFileDialog();
                dlg.FileName = (string)listBox1.SelectedItem;
                if (dlg.ShowDialog() == DialogResult.OK)
                {
                    string filePath = dlg.FileName.Substring(0, dlg.FileName.LastIndexOf("\\"));

                    Ftp    ftp     = FtpControl.GetFtp("WorkOrder/" + model.WOCode);
                    string message = ftp.Download(filePath, (string)listBox1.SelectedItem);
                    if (message == "")
                    {
                        message = "下载完成!";
                    }
                    MessageBox.Show(message);
                }
            }
            #endregion
        }
예제 #2
0
        private void GetFTPFileList(string path)
        {
            #region 获取FTP文件列表

            var ftp = FtpControl.GetFtp("WorkOrder/");

            if (ftp.FolderExist(model.WOCode))
            {
                ftp = FtpControl.GetFtp("WorkOrder/" + model.WOCode);

                string[] sArray = ftp.GetFileList();

                if (sArray != null && sArray.Length > 0)
                {
                    this.listBox1.Items.Clear();
                    foreach (string s in sArray)
                    {
                        string[] sAry = s.Split(new char[] { ' ' });
                        this.listBox1.Items.Add(s);
                    }
                }
            }

            #endregion
        }
예제 #3
0
파일: FtpStore.cs 프로젝트: nerai/Zysl
        public FtpStore(string server, string user, string pass, bool passive, string root)
        {
            _Ftp = new FtpControl (server, user, pass, passive);
            _Root = root;
            _Tmp = _Root + "/tmp";
            _Ftp.CreateDirectory (_Root);
            _Ftp.CreateDirectory (_Tmp);

            /*
             * Recovery process, see FileStore class
             */
            foreach (var file in ListKeys (_Tmp)) {
                // todo: getfilelist sollte bereits nach cache prefix filtern damit nicht so viel ankommt
                // todo: prüfen wie genau file path augebaut ist und ob er zu lang ist (enthält komplettes CWD?)

                if (_Ftp.Exists (_Root + file)) {
                    if (!_Ftp.Delete (_Tmp + file)) {
                        throw new IOException ("FTP recovery process failed: Unable to delete temp file " + file);
                    }
                }
                else {
                    if (!_Ftp.Rename (_Tmp + file, _Root + file)) {
                        throw new IOException ("FTP recovery process failed: Unable to move temp file " + file);
                    }
                }
            }
        }
예제 #4
0
 private void btn_delfile_Click(object sender, EventArgs e)
 {
     #region  除文档
     if (listBox1.SelectedItem == null)
     {
         MsgBox.ShowInfoMsg("请选择要删除的记录!");
     }
     else if (MsgBox.ShowYesNoMsg("确定删除选中文档?") == DialogResult.Yes)
     {
         Ftp ftp = FtpControl.GetFtp("WorkOrder/" + model.WOCode);
         ftp.DeleteFileName((string)listBox1.SelectedItem);
         this.GetFTPFileList(model.WOCode);
     }
     #endregion
 }
예제 #5
0
        private bool UpLoadFile(params string[] fileNames)
        {
            #region   图纸
            if (fileNames.Length < 1)
            {
                MsgBox.ShowInfoMsg("选择需要上传的文件!");
                return(false);
            }

            try
            {
                var ftp = FtpControl.GetFtp("WorkOrder/" + model.WOCode);

                foreach (string fileName in fileNames)
                {
                    FileInfo file = new FileInfo(fileName);

                    if (ftp.FileExist(file.Name))
                    {
                        MsgBox.ShowInfoMsg("FTP已存在相同名称的文件:" + file.Name);
                        return(false);
                    }
                }

                foreach (string fileName in fileNames)
                {
                    FileInfo file    = new FileInfo(fileName);
                    string   message = ftp.Upload(file.FullName);
                    if (message != "")
                    {
                        MsgBox.ShowInfoMsg(message);
                        return(false);
                    }
                }
            }
            catch (Exception ex)
            {
                MsgBox.ShowInfoMsg(ex.ToString());
                return(false);
            }

            return(true);

            #endregion
        }