I have written a simple wrapper for WinSCP in C#. I have written it to simplify SFTP connections I will needing to perform. public class WinSCPConn : IDisposable{        //private fields        private SessionOptions sessionOptions;        private TransferOptions transferOptions;        private Session session;        //public properties        public bool IsSessionOpen { get { return session.Opened; } }        public WinSCPConn(string hostname, string username, string password)        {            sessionOptions = new SessionOptions();            sessionOptions.Protocol = Protocol.Sftp;            sessionOptions.HostName = hostname;            sessionOptions.PortNumber = 22;            sessionOptions.Password = password;            sessionOptions.UserName = username;            sessionOptions.Timeout = new TimeSpan(0, 3, 0);            sessionOptions.GiveUpSecurityAndAcceptAnySshHostKey = true;            transferOptions = new TransferOptions();            transferOptions.TransferMode = TransferMode.Binary;            try            {                session = new Session();                session.ExecutablePath = Properties.Settings.Default.WinSCPPath;            }            catch (SessionLocalException)            {                throw;            }         }        public void Open()        {            try            {                if (session.Opened == false)                {                    session.Open(sessionOptions);                }            }            catch (SessionRemoteException)            {                throw;            }        }        public TransferOperationResult SendFile(string SourceFile, string DestFile)        {            TransferOperationResult result;            try            {                 result = session.PutFiles(SourceFile, DestFile, false, transferOptions);                 return result;            }            catch (SessionRemoteException)            {                 throw;            }          }        public void CreateDirectory(string FolderPath)        {            try            {                if (!session.FileExists(FolderPath))                {                    session.CreateDirectory(FolderPath);                }            }            catch (SessionRemoteException)            {                throw;            }        }        public void Close()        {            if (session.Opened == true)            {                session.Dispose();            }        }        public void Dispose()        {            Close();        } }It would be used as follows: using (WinSCPConn conn = new WinSCPConn(host, username, password)) {                             conn.Open();      conn.CreateDirectory(/path/);      conn.SendFile(@C:\file.txt,/path/file.txt); }My questions are as follows:How is my exception handling?Is there too much going on in the constructor?
WinSCP IDisposable Wrapper
c#;.net;wrapper
TimeoutsessionOptions.Timeout = new TimeSpan(0, 3, 0);Instead of using the TimeSpan constructor, I would instead use the TimeSpan.FromX methods.  In this case, it would be TimeSpan.FromMinutes:sessionOptions.Timeout = TimeSpan.FromMinutes(3);It is a little more obvious that the timeout is 3 minutes now.PortsessionOptions.PortNumber = 22;For this, I see two options:Take port as a parameterOmit the lineIf you are always using the default port, you can omit the assignment.  According to the WinSCP API Doc, leaving the port to the default of 0 will cause it to use the protocol default (22 for SFTP).Keep in mind that always is not always always :)Session Creationtry{    session = new Session();    session.ExecutablePath = Properties.Settings.Default.WinSCPPath;}catch (SessionLocalException){    throw;} This part actually has two problems with it:the catch does not do anything aside from re-throw the exceptionyou are throwing an exception in the constructor of an IDisposable type, which breaks using statementsFor the first point, you could just remove the try/catch.  It only has a purpose if you are planning on doing something in the catch.  This is true for all of your try/catch blocks.The next point could be solved with lazy initialization of the session.  If you change the if statement within Open to do a null check, you can create and open the session there.public void Open(){    if (session == null)    {        session = new Session();        session.ExecutablePath = Properties.Settings.Default.WinSCPPath;        session.Open(sessionOptions);    }}Perhaps more robust, though, is just to add a separate if check and do the creation/opening separately:public void Open(){    if (session == null)    {        session = new Session();        session.ExecutablePath = Properties.Settings.Default.WinSCPPath;    }    if (session.Opened == false)    {        session.Open(sessionOptions);    }}IDisposableThere are a couple things you may want to address with your IDispoable implementation:suppress finalizationsupport cases where Dispose is never calledallow sub-classes to override disposal behavior or seal the classThe first one is pretty easy:public void Dispose(){   Close();   GC.SuppressFinalize(this);}The second one depends largely on how the WinSCP Session class is written.  You may need to ensure that the session is closed even if Dispose is never called, though you only need to worry about actually disposing of it when Dispose is called.For the last one, I would just mark the class as sealed, since you have neither virtual nor protected members.  Otherwise, you should provide a virtual Dispose method.  Generally, when doing so, your empty Dispose remains non-virtual, and you would provide an additional protected overload which takes in a boolean.For more information, see:Code analysis rule CA1063 and the MSDN page on Implementing a Dispose Method.