Beispiel #1
0
        // Upload a file using FtpWebRequest
        public static void UploadDemo()
        {
            FtpWebRequest req = (FtpWebRequest)WebRequest.Create("ftp://192.168.1.251/demofile.bmp");

            //req.Username = "******";
            //req.Password = "******";
            req.Method     = "PUT";             // STOR or PUT
            req.BinaryMode = true;
            Stream writeStream = req.GetResponse().GetResponseStream();

            FileStream fs = new FileStream(@"c:\temp\cool.bmp", FileMode.Open);

            byte[] buffer = new byte[bufferSize];
            int    read;

            while ((read = fs.Read(buffer, 0, bufferSize)) > 0)
            {
                writeStream.Write(buffer, 0, bufferSize);
            }
            writeStream.Close();
            req.Close();
            fs.Close();
        }