Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void button1_Click(object sender, EventArgs e)
- {
- Boolean ftpMode = true;
- // Get the object used to communicate with the server.
- FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp://100.100.100.83");
- request.Method = WebRequestMethods.Ftp.UploadFileWithUniqueName;
- // This example assumes the FTP site uses anonymous logon.
- request.Credentials = new NetworkCredential("access", "1234!");
- if (ftpMode == true)
- {
- request.KeepAlive = false;
- }
- // Copy the contents of the file to the request stream.
- StreamReader sourceStream = new StreamReader("C:/blacklist/ticketsblacklist.csv");
- byte[] fileContents = Encoding.UTF8.GetBytes(sourceStream.ReadToEnd());
- sourceStream.Close();
- request.ContentLength = fileContents.Length;
- Stream requestStream = request.GetRequestStream();
- requestStream.Write(fileContents, 0, fileContents.Length);
- requestStream.Close();
- FtpWebResponse response = (FtpWebResponse)request.GetResponse();
- Console.WriteLine("Upload File Complete, status {0}", response.StatusDescription);
- response.Close();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement