Example #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();
        }
Example #2
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();
        }