因为我在这里使用“使用”,如果在 TRY 中的任何地方出现异常,FtpWebRequest、FtpWebRespons 和 responseStream 会自动关闭吗?
Try
Dim request As FtpWebRequest = CType(WebRequest.Create(""), FtpWebRequest)
request.Method = WebRequestMethods.Ftp.ListDirectoryDetails
request.Credentials = New NetworkCredential("", "")
Using response As FtpWebResponse = CType(request.GetResponse(), FtpWebResponse)
Using responseStream As Stream = response.GetResponseStream()
Using reader As New StreamReader(responseStream)
TextBox1.Text = reader.ReadToEnd
TextBox1.Text += vbNewLine
TextBox1.Text += vbNewLine
' Use the + for appending (set the textbox to multiline)
End Using
End Using
End Using
Catch ex As Exception
MessageBox.Show(ex.Message.ToString())
End Try