PowerTCP SSH and SFTP for .NET
Connect() Method




Connects to the SSH-2 server specified by Connection.RemoteEndPoint.
Syntax
'Declaration
 
Public Overloads Sub Connect() 
'Usage
 
Dim instance As SshConnection
 
instance.Connect()
public void Connect()
public: void Connect(); 
public:
void Connect(); 
Exceptions
ExceptionDescription
System.IO.IOExceptionIf any problem occurs, e.g., the server's host key is not accepted by the user's HostKey event handler or there is problem during the initial crypto setup (e.g., the signature sent by the server is wrong).
System.TimeoutException The TCP connection and key exchange could not be completed within the specified timeout period.
HttpProxyException The specified HTTP proxy failed to operate as expected.
Remarks

Use Connection.RemoteEndPoint and Connection.LocalEndPoint to set remote and local address and port.

When the server presents its host key, raises the HostKey event to ask for permission to proceed. If no handler is registered for the HostKey event, then any host key will be accepted - this is NOT recommended, since it makes man-in-the-middle attacks VERY easy (somebody could put a proxy SSH server between you and the real server).

Note: The HostKey event is raised before doing any crypto calculations (i.e., diffie-hellman). Therefore, if you do not like the presented host key then no CPU cycles are wasted (and the server has less information about the client).

However, it is still possible that the server presented a fake host key: the server cheated (typically a sign for a man-in-the-middle attack) and is not able to generate a signature that matches its host key. The library will detect such a scenario later when checking the signature (the signature cannot be checked before having completed the diffie-hellman exchange).

Note 2: See the ComponentBase.SynchronizingObject property for important information on updating UI controls from within the HostKey event.

Note 3: This method will block as long as the key exchange of the underlying connection has not been completed.

The technique used to invoke this method is dependent upon the value of ThreadingModel. If ThreadingModel.Free, this method executes on the current thread and returns when complete (this is standard for creating applications in multi-threading environments like .NET). If ThreadingModel.ApartmentBlocking, this method blocks and processes windows UI messages while a worker thread executes (this is useful for making a simple blocking call in an apartment model environment like VB6). If ThreadingModel.ApartmentAsync, this method immediately returns after starting a worker thread that executes asynchronously (this is useful for creating advanced communications applications in an apartment model environment like VB6). The StateChanged event will be raised upon completion, or the Error event raised if an exception is thrown.

See Also

Reference

SshConnection Class
SshConnection Members
Overload List


PowerTCP SSH and SFTP for .NET Documentation Version 7.0
© 2023 Dart Communications. All Rights Reserved.
Send comments on this topic