Thông tin FTP Server
- URL: ftp://156.67.222.163/
- Username: `u657022003.ftpuser`
- Password:
123456789-Aa
Code cho phép upload bằng giao thức FTP
csharp
1public static void Main ()2 {3 // Get the object used to communicate with the server.4 FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp://www.contoso.com/test.htm");5 request.Method = WebRequestMethods.Ftp.UploadFile;6 7 // This example assumes the FTP site uses anonymous logon.8 request.Credentials = new NetworkCredential("anonymous", "[email protected]");9 10 // Copy the contents of the file to the request stream.11 byte[] fileContents;12 using (StreamReader sourceStream = new StreamReader("testfile.txt"))13 {14 fileContents = Encoding.UTF8.GetBytes(sourceStream.ReadToEnd());15 }16 17 request.ContentLength = fileContents.Length;18 19 using (Stream requestStream = request.GetRequestStream())20 {21 requestStream.Write(fileContents, 0, fileContents.Length);22 }23 24 using (FtpWebResponse response = (FtpWebResponse)request.GetResponse())25 {26 Console.WriteLine($"Upload File Complete, status {response.StatusDescription}");27 }28 }
