Esempio n. 1
0
        private async Task UpLoadFile(FtpFile selected)
        {
            FtpTransferResult result = new FtpTransferResult();

            result.ResultType  = FtpResultType.Uploading;
            result.Info        = this._localPath + selected.Name;
            result.Target      = this._remotePath + selected.Name;
            result.TotalLength = selected.ByteSize;
            result.Time        = DateTime.Now;
            result.Process     = 0;
            result.Position    = 0;
            this._ftpResults.Add(result);
            this._queuedMissions.Add(result);
            try
            {
                await this.FtpService.UpLoadFileAsync(result);

                this._ftpResults.Add(new FtpTransferResult
                {
                    ResultType = FtpResultType.Uploaded,
                    Info       = result.Info,
                    Target     = result.Target,
                    Process    = 100,
                    Time       = DateTime.Now
                });
                this._remoteValue.Clear();
                this._queuedMissions.Remove(result);
                await this.ListRemoteFiles();
            }
            catch (Exception)
            {
                this._queuedMissions.Remove(result);
                throw;
            }
        }
Esempio n. 2
0
        public FtpFile AddFile(string FileName)
        {
            //blokujemy duplikaty
            foreach (FtpFile File in Files)
            {
                if (File.FileName.Equals(FileName))
                {
                    return(File);
                }
            }

            FtpFile NewFile = new FtpFile(this, FileName);

            Files.Add(NewFile);
            return(NewFile);
        }
Esempio n. 3
0
        private async Task LoadDrives()
        {
            DriveInfo[] drives = await Task.Run <DriveInfo[]>(() => DriveInfo.GetDrives());

            this._drives = new FtpFile[drives.Length];
            for (int i = 0; i < drives.Length; i++)
            {
                var tmp = new FtpFile();
                tmp.Name     = drives[i].RootDirectory.Name;
                tmp.Name     = tmp.Name.Substring(0, tmp.Name.Length - 1);
                tmp.Type     = 1;
                tmp.ByteSize = drives[i].TotalSize;
                tmp.Size     = (drives[i].AvailableFreeSpace >> 9) + "GB / " +
                               (drives[i].TotalSize >> 9) + "GB";
                this._drives[i] = tmp;
                this._localValue.Add(tmp);
            }
        }
Esempio n. 4
0
        public async Task <IEnumerable <FtpFile> > GetLocalFileListAsync(string dir)
        {
            List <FtpFile> files     = new List <FtpFile>();
            DirectoryInfo  directory = new DirectoryInfo(dir);

            FileSystemInfo[] filesysteminfos = await Task.Run <FileSystemInfo[]>(() => directory.GetFileSystemInfos());

            Parallel.ForEach <FileSystemInfo, List <FtpFile> >(filesysteminfos, () => new List <FtpFile>(),
                                                               (FileSystemInfo fs, ParallelLoopState loopstate, List <FtpFile> localfiles) =>
            {
                FtpFile file = new FtpFile();
                if ((fs.Attributes & FileAttributes.System) == FileAttributes.System)
                {
                    return(localfiles);
                }
                if ((fs.Attributes & FileAttributes.Directory) == FileAttributes.Directory)
                {
                    file.Size = "";
                    file.Type = 1;
                }
                else
                {
                    file.ByteSize = ((FileInfo)fs).Length;
                    file.Size     = file.ByteSize + "Bytes";
                    file.Type     = 2;
                }
                file.Name     = fs.Name;
                file.Modified = fs.LastWriteTime;
                localfiles.Add(file);
                return(localfiles);
            },
                                                               localfiles =>
            {
                Monitor.Enter(files);
                files.AddRange(localfiles);
                Monitor.Exit(files);
            });
            return(files.OrderBy(item => item.Type)
                   .CreateOrderedEnumerable(item => item.Name, Comparer <string> .Default, false));
        }
Esempio n. 5
0
        private async void btn_Connect_Click(object sender, RoutedEventArgs e)
        {
            if (this._remoteValue.Count != 0)
            {
                this._remoteValue.Clear();
            }
            this._remotePath.Clear();
            this._ftpResults.Add(new FtpTransferResult
            {
                ResultType = FtpResultType.Connecting,
                Info       = "Connecting Host: " + this.FtpService.Ftp.Host,
                Process    = 100,
                Time       = DateTime.Now
            });
            this._remotePath.Append("/");
            try
            {
                FtpFile.InitlizePaser();
                await this.ListRemoteFiles();

                this._ftpResults.Add(new FtpTransferResult
                {
                    ResultType = FtpResultType.Connected,
                    Info       = "Host: " + this.FtpService.Ftp.Host + " Connected",
                    Process    = 100,
                    Time       = DateTime.Now
                });
                this._connected = true;
            }
            catch (Exception ex)
            {
                this._ftpResults.Add(new FtpTransferResult
                {
                    ResultType = FtpResultType.Error,
                    Info       = ex.Message,
                    Process    = 100,
                    Time       = DateTime.Now
                });
            }
        }
Esempio n. 6
0
        public async Task <IEnumerable <FtpFile> > GetRemoteFileListAsync(string subDir = "/")
        {
            List <FtpFile> files   = new List <FtpFile>();
            FtpWebRequest  request = FtpWebRequest.Create("ftp://" +
                                                          this.Ftp.Host + ":" + this.Ftp.Port + subDir) as FtpWebRequest;

            request.Credentials      = new NetworkCredential(this.Ftp.UserName, this.Ftp.Password);
            request.Method           = WebRequestMethods.Ftp.ListDirectoryDetails;
            request.Timeout          = 10000;
            request.ReadWriteTimeout = 10000;
            using (var response = await request.GetResponseAsync() as FtpWebResponse)
                using (var stream = response.GetResponseStream())
                    using (var reader = new StreamReader(stream))
                    {
                        while (reader.Peek() > -1)
                        {
                            files.Add(FtpFile.Parse(await reader.ReadLineAsync()));
                        }
                    }
            return(files.OrderBy(item => item.Type)
                   .CreateOrderedEnumerable(item => item.Name, Comparer <string> .Default, false));
        }
Esempio n. 7
0
        private async Task DownLoadFile(FtpFile selected)
        {
            FtpTransferResult result = new FtpTransferResult();

            result.ResultType  = FtpResultType.Downloading;
            result.Info        = this._remotePath + selected.Name;
            result.Target      = this._localPath + selected.Name;
            result.TotalLength = selected.ByteSize;
            result.Time        = DateTime.Now;
            result.Position    = 0;
            result.Process     = (double)result.Position / result.TotalLength * 100;
            this._ftpResults.Add(result);
            this._queuedMissions.Add(result);
            try
            {
                await this.FtpService.DownLoadFileAsync(result, this._cancelTokanSource);

                this._ftpResults.Add(new FtpTransferResult
                {
                    ResultType = FtpResultType.Downloaded,
                    Info       = result.Info,
                    Target     = result.Target,
                    Process    = 100,
                    Time       = DateTime.Now
                });
                this._localValue.Clear();
                this._queuedMissions.Remove(result);
                await this.ListLocalFiles();
            }
            catch (Exception)
            {
                this._unCompletedMissions.Add(result);
                this._queuedMissions.Remove(result);
                File.Delete(result.Target);
                throw;
            }
        }