In a code like this
using (var sftp = new SftpClient(_host, _userName, _password))
{
sftp.Connect();
// Do some work with sftp
sftp.Disconnect();
}
Is sftp.Disconnect() call necessary or will using block (Dispose/Close/whatever) close connection automatically?
No, you don't need to call Disconnect
within a using
block.
SftpClient
automatically calls the Disconnect
method when disposing of the object.
See relevant source code:
https://github.com/sshnet/SSH.NET/blob/7bdfc9e615b736b2762f5cd83c31a5f669663ff6/src/Renci.SshNet/BaseClient.cs#L409-L428
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With