Example #1
0
 private static Task DeleteDirectory(IFtpClient client, string remoteDirectoryPath)
 {
     return(Task.Run(() =>
     {
         client.DeleteDirectory(remoteDirectoryPath);
     }));
 }
Example #2
0
        private void Delete_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("是否删除该文件夹", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question)
                == DialogResult.Cancel)
            {
                return;
            }
            TreeNode pNode = this.SelectedNode;
            int      ID    = this.GetNodeID(pNode);

            IFtpClient pFtpClient = SysDBConfig.GetInstance().GetFtpClient("CHXQ");

            pFtpClient.Connect();
            pFtpClient.DeleteDirectory(GetFtpPathByNode(pNode));
            pFtpClient.Close();

            string sql = string.Format("delete from up_dirs where id={0}", ID);

            IDataBase pDataBase = SysDBConfig.GetInstance().GetOleDataBase("OrclConn");

            pDataBase.OpenConnection();
            pDataBase.ExecuteNonQuery(sql);
            pDataBase.CloseConnection();

            this.RefreshSubTreeView(pNode.Parent);
        }
Example #3
0
        private void SyncDirectory(IFtpClient client, string remotePath, string localPath, bool isDel)
        {
            var localFolder = new DirectoryInfo(localPath);
            var infos       = localFolder.GetFileSystemInfos();

            foreach (var info in infos)
            {
                if (!client.IsConnected)
                {
                    client.Connect();
                }
                if (info is FileInfo)
                {
                    var size = (info as FileInfo).Length;

                    var remoteFile = Path.Combine(remotePath, info.Name);

                    if (!client.FileExists(remoteFile) || client.GetFileSize(remoteFile) != size)
                    {
                        client.UploadFile(info.FullName, remoteFile);

                        Logger.Info($"Uploaded==>{info.FullName}");
                    }
                }
                else if (info is DirectoryInfo)
                {
                    var remoteFile = Path.Combine(remotePath, info.Name);

                    if (!client.DirectoryExists(remoteFile))
                    {
                        client.CreateDirectory(remoteFile);

                        Logger.Info($"CreateFtpDirectory==>{remoteFile}");
                    }
                    SyncDirectory(client, Path.Combine(remotePath, info.Name), info.FullName, isDel);
                }
            }

            if (isDel)
            {
                var items = client.GetListing(remotePath);
                foreach (var item in items)
                {
                    if (infos.All(info => info.Name != item.Name))
                    {
                        if (item.Type == FtpFileSystemObjectType.File)
                        {
                            client.DeleteFile(item.FullName);
                        }
                        else if (item.Type == FtpFileSystemObjectType.Directory)
                        {
                            client.DeleteDirectory(item.FullName);
                        }

                        Logger.Info($"DeletedFtp==>{item.FullName}");
                    }
                }
            }
        }