Esempio n. 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();
        }
Esempio n. 2
0
        public void uploadFile(string saveName, string fname, string path, int continueTransport = 0)
        {
            cs.CWD(path);
            FileStream fs = new FileStream(fname, FileMode.Open, FileAccess.Read);

            if (continueTransport == 1)
            {
                long fileSize = cs.SIZE(path + saveName);
                fs.Position = fileSize;
            }
            Console.WriteLine(fs.Position);
            int        port = cs.PASV();
            DataSocket ds   = new DataSocket(this.serverIp, port);

            if (continueTransport == 1)
            {
                cs.APPE(saveName);
            }
            else
            {
                cs.STOR(saveName);
            }
            ds.readFileStream(fs);
            //cs.DATA_END();
        }
Esempio n. 3
0
        public void uploadFile(string saveName, string fname, string path)
        {
            cs.CWD(path);
            int        port = cs.PASV();
            DataSocket ds   = new DataSocket(this.serverIp, port);

            cs.STOR(saveName);
            FileStream fs = new FileStream(fname, FileMode.Open, FileAccess.Read);

            ds.readFileStream(fs);
            //cs.DATA_END();
        }
Esempio n. 4
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);
        }
Esempio n. 5
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();
        }