1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
| FtpWebRequest req = FtpWebRequest.Create(new Uri("ftp://127.0.0.1/pic.png")) as FtpWebRequest;
NetworkCredential n = new NetworkCredential("nightstardawn", "night123");
req.Credentials = n;
req.KeepAlive = false;
req.Method = WebRequestMethods.Ftp.UploadFile;
req.UseBinary = true;
Stream upDateStream = req.GetRequestStream();
using (FileStream file = File.OpenRead(Application.streamingAssetsPath + "/test.png")) { byte[] bytes = new byte[1024]; int contetntLenght = file.Read(bytes, 0, bytes.Length); while (contetntLenght != 0) { upDateStream.Write(bytes, 0, contetntLenght); contetntLenght = file.Read(bytes, 0, bytes.Length); } file.Close(); upDateStream.Close(); print("上传结束"); }
|