Beispiel #1
0
        public void downloadFile(String fname, string saveName)
        {
            long       fileSize = cs.SIZE(fname);
            int        port     = cs.PASV();
            DataSocket ds       = new DataSocket(this.serverIp, port);

            cs.RETR(fname);

            /*
             * if (File.Exists(saveName))
             * {
             *  FileStream fs = File.OpenRead(saveName);
             *  long currentSize = fs.Length;
             *  cs.REST(currentSize);
             * }
             * else
             */
            using (FileStream fs = File.Create(saveName))
            {
                int currentSize = 0;
                while (currentSize < fileSize)
                {
                    ds.RECV();
                    currentSize += ds.Size();
                    ds.writeFileStream(fs);
                }
            }
            cs.DATA_END();
        }
Beispiel #2
0
        public List <string> getNameList(string pathName, char type)
        {
            int        port = cs.PASV();
            DataSocket ds   = new DataSocket(this.serverIp, port);

            cs.LIST(pathName);
            string message = "";

            while (true)
            {
                ds.RECV();
                if (ds.Size() == 0)
                {
                    break;
                }
                message += ds.getMessage();
            }
            message = message.Trim();
            cs.DATA_END();
            string[]      infoList = message.Split('\n');
            List <string> nameList = new List <string>();

            for (int i = 0; i < infoList.Length; ++i)
            {
                String info = infoList[i].Trim();
                int    id   = info.Length - 1;
                while (info[id] != ' ')
                {
                    id--;
                }
                String name = info.Substring(id + 1, info.Length - id - 1);
                if (info[0] == type && name != "." && name != "..")
                {
                    nameList.Add(name);
                }
            }
            foreach (string file in nameList)
            {
                Console.WriteLine(file);
            }
            return(nameList);
        }
Beispiel #3
0
        public void downloadFile(String fname, string saveName, int continueTransport = 0)
        {
            long fileSize    = cs.SIZE(fname);
            long currentSize = 0;

            if (continueTransport == 1)
            {
                using (FileStream fs = File.OpenRead(saveName))
                {
                    currentSize = fs.Length;
                    cs.REST(currentSize);
                }
            }
            else
            {
                using (FileStream fs = File.Create(saveName))
                    currentSize = 0;
            }
            int        port = cs.PASV();
            DataSocket ds   = new DataSocket(this.serverIp, port);

            cs.RETR(fname);

            using (FileStream fs = File.OpenWrite(saveName))
            {
                fs.Position = fs.Length;
                while (currentSize < fileSize)
                {
                    ds.RECV();
                    currentSize += ds.Size();
                    ds.writeFileStream(fs);
                    Console.Write(currentSize);
                    Console.Write(" ");
                    Console.WriteLine(fileSize);
                }
            }
            cs.DATA_END();
        }