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 ausing
block.SftpClient
automatically calls theDisconnect
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