예제 #1
0
        /// <summary>
        /// 上传
        /// </summary>
        /// <param name="localfile"></param>
        /// <param name="remotefile"></param>
        /// <param name="mode">模式</param>
        /// <returns></returns>
        public Int64 UploadFile(String localfile, String remotefile, FtpTransportMode mode)
        {
            if (String.IsNullOrEmpty(localfile))
            {
                throw new ArgumentNullException("localfile", "没有指定本地文件名。");
            }

            var fi = new FileInfo(localfile);

            if (!fi.Exists)
            {
                throw new Exception("本地文件不存在。");
            }

            if (String.IsNullOrEmpty(remotefile))
            {
                remotefile = fi.Name;
            }

            var size = Client.UploadFile(localfile, FtpPath.Combine(Path, remotefile), mode);

            Reload();

            return(size);
        }
예제 #2
0
        private void Load(String line)
        {
            if (String.IsNullOrEmpty(line))
            {
                return;
            }
            line = line.Replace("\n", null);

            var lines = line.Split(new Char[] { '\r' }, StringSplitOptions.RemoveEmptyEntries);

            Clear();
            foreach (var item in lines)
            {
                //FtpFile f = new FtpFile(item, Path);
                var f = FtpFile.Create(item, Path);
                if (f == null)
                {
                    continue;
                }

                f.Parent = this;

                if (!f.IsDirectory && Client != null)
                {
                    Client.Files[FtpPath.Combine(Path, f.FileName)] = f;
                }

                Add(f);
            }
        }
예제 #3
0
        /// <summary>
        /// 建立子目录
        /// </summary>
        /// <param name="name"></param>
        public void CreateDirectory(String name)
        {
            if (Contains(name))
            {
                throw new Exception("目录[" + name + "]已存在!");
            }

            Client.MakeDirectory(FtpPath.Combine(Path, name));

            ////清缓存
            //Directories = null;
            //Load(Client.ListDirectoryDetailsString(Path));

            var d = Client.ListDirectoryDetails(FtpPath.Combine(Path, name));

            d.Parent = this;
            Directories.Add(name, d);
        }