In this case, a little cleaner, uses fewer threads and properly closes them when this is done.
Uri requestUri = new Uri(string.Concat("bbbbb", "bbbbbb", "bbb/", hj, "/", hjj, ".txt")); FtpWebRequest request = (FtpWebRequest)WebRequest.Create(requestUri); request.Credentials = new NetworkCredential("bbbbb", "bbbbbb"); request.Method = WebRequestMethods.Ftp.UploadFile; request.UsePassive = true; byte[] fileContents = File.ReadAllBytes(@"oo.txt"); request.ContentLength = fileContents.Length; using (Stream requestStream = request.GetRequestStream()) { requestStream.Write(fileContents, 0, fileContents.Length); }
WebRequest.Abort designed to terminate asynchronous operations that you do not have. Do not call it here. Please examine the using statement that I included, as suggested in the comments of Mitch Wheat. It will automatically delete the stream object.
Like other questions, of course, someone can use the same credentials to log into the FTP server, but not as a result of your code. The same credentials will always succeed. I think you are worried that the connection is active, but this is a problem for the server.
source share