Ejemplo n.º 1
0
        public string nextDir()
        {
            this.ptr.seek += 1;

            if (this.ptr.seek >= this.ptr.dirCount())
            {
                if (this.ptr == this)
                {
                    this.seek = -1;
                    return(this.name);
                }
                else
                {
                    this.ptr.seek = -1;
                    this.ptr      = this.ptr.root;
                    this.level--;
                    return(this.nextDir());
                }
            }

            this.ptr = this.ptr.katalogi[this.ptr.seek];
            this.level++;

            return(this.ptr.getName());
        }
Ejemplo n.º 2
0
        public Katalog(string name)
        {
            this.katalogi = new List <Katalog>();
            this.pliki    = new List <string>();
            this.seek     = -1;
            this.level    = 0;
            this.ptr      = this;
            this.root     = null;
            this.name     = name;
            this.max      = Int32.MaxValue;

            string[] wynik = name.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries);

            if (wynik.Length > 0)
            {
                this.shortName = "/" + wynik[wynik.Length - 1];
            }
            else
            {
                this.shortName = "/";
            }
        }
Ejemplo n.º 3
0
        public void Reslove(string dane)
        {
            string[] wynik = dane.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);

            foreach (string Q in wynik)
            {
                string name = this.getFileName(Q);

                if (Q[0] == 'd')
                {
                    if (this.level < this.max)
                    {
                        Katalog temp = new Katalog(this.ptr.getName() + "/" + name);
                        temp.root      = this.ptr;
                        temp.shortName = this.ptr.shortName + "/" + name;
                        this.ptr.katalogi.Add(temp);
                    }
                }
                else
                {
                    this.ptr.pliki.Add(name);
                }
            }
        }
Ejemplo n.º 4
0
        public void Run()
        {
            this.polecenia.Connect(this.adres, 21);

            if (this.polecenia.Poll(0, SelectMode.SelectRead) && this.polecenia.Available == 0)
            {
                this.polecenia.Close();
                throw new Exception("Nie nawiązano połączenia.");
            }

            string wynik = "";

            wynik = this.getAnswer(FtpError.Connect);

            this.execCommand(FtpCommand.User, this.konto);
            wynik = this.getAnswer(FtpError.Login);

            this.getPassword();

            this.execCommand(FtpCommand.Pass, this.hasło);
            wynik = this.getAnswer(FtpError.Password);

            this.execCommand(FtpCommand.Cwd, this.katalog);
            wynik = this.getAnswer(FtpError.Dir);

            this.execCommand(FtpCommand.Pasv);
            wynik = this.getAnswer(FtpError.Pasive);

            this.Connect(wynik);

            this.execCommand(FtpCommand.List);
            wynik = this.getAnswer(FtpError.List);
            wynik = getData(FtpError.List);

            Katalog pliki = new Katalog(this.katalog);

            pliki.setMax(this.maxDir);
            pliki.Reslove(wynik);

            wynik = this.getAnswer(FtpError.List);

            while (true)
            {
                wynik = pliki.nextDir();
                if (wynik == this.katalog)
                {
                    break;
                }

                this.execCommand(FtpCommand.Cwd, wynik);
                wynik = this.getAnswer(FtpError.Dir);

                this.execCommand(FtpCommand.Pasv);
                wynik = this.getAnswer(FtpError.Pasive);

                this.Connect(wynik);

                this.execCommand(FtpCommand.List);
                wynik = this.getAnswer(FtpError.List);
                wynik = getData(FtpError.List);

                pliki.Reslove(wynik);

                wynik = this.getAnswer(FtpError.List);
            }

            this.execCommand(FtpCommand.Typei);
            wynik = this.getAnswer(FtpError.Type);

            bool first = false;

            while (true)
            {
                string current = this.katalog;

                if (first)
                {
                    current = pliki.nextDir();

                    if (current == this.katalog)
                    {
                        break;
                    }
                }

                string folder = this.cel + pliki.getShortName();

                if (!Directory.Exists(folder))
                {
                    Directory.CreateDirectory(folder);
                }

                this.execCommand(FtpCommand.Cwd, current);
                wynik = this.getAnswer(FtpError.Dir);
                string[] wyniki = pliki.getFiles();

                foreach (string Q in wyniki)
                {
                    DateTime czas = DateTime.Now;

                    if (File.Exists(folder + "/" + Q))
                    {
                        DateTime mtime = File.GetLastWriteTime(folder + "/" + Q);

                        this.execCommand(FtpCommand.Mdtm, Q);
                        wynik = this.getAnswer(FtpError.Mtime);

                        czas = this.getDate(wynik);

                        if (mtime >= czas)
                        {
                            continue;
                        }
                    }
                    else
                    {
                        this.execCommand(FtpCommand.Mdtm, Q);
                        wynik = this.getAnswer(FtpError.Mtime);

                        czas = this.getDate(wynik);
                    }

                    this.execCommand(FtpCommand.Pasv);
                    wynik = this.getAnswer(FtpError.Pasive);

                    this.Connect(wynik);

                    this.execCommand(FtpCommand.Retr, Q);
                    wynik = this.getAnswer(FtpError.List);
                    this.getFile(folder, Q, czas);
                    wynik = this.getAnswer(FtpError.Retr);
                    Console.WriteLine("Pobrano plik: " + Q);
                }
                first = true;
            }

            this.execCommand(FtpCommand.Quit);
            this.getAnswer(FtpError.Quit);
        }