Advertisement
Guest User

Untitled

a guest
Jul 20th, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 1.94 KB | None | 0 0
  1. '  This example assumes Chilkat SSH/SFTP to have been previously unlocked.
  2. '  See Unlock SSH for sample code.
  3.  
  4. Dim ssh As New Chilkat.Ssh
  5.  
  6. Dim port As Integer = 22
  7. Dim success As Boolean = ssh.Connect("the-ssh-server.com",port)
  8. If (success <> True) Then
  9.     Console.WriteLine(ssh.LastErrorText)
  10.     Exit Sub
  11. End If
  12.  
  13.  
  14. '  Authenticate using login/password:
  15. success = ssh.AuthenticatePw("theSshLogin","theSshPassword")
  16. If (success <> True) Then
  17.     Console.WriteLine(ssh.LastErrorText)
  18.     Exit Sub
  19. End If
  20.  
  21.  
  22. '  Send some commands and get the output.
  23. Dim strOutput As String = ssh.QuickCommand("df","ansi")
  24. If (ssh.LastMethodSuccess <> True) Then
  25.     Console.WriteLine(ssh.LastErrorText)
  26.     Exit Sub
  27. End If
  28.  
  29. Console.WriteLine("---- df ----")
  30. Console.WriteLine(strOutput)
  31.  
  32. strOutput = ssh.QuickCommand("echo hello world","ansi")
  33. If (ssh.LastMethodSuccess <> True) Then
  34.     Console.WriteLine(ssh.LastErrorText)
  35.     Exit Sub
  36. End If
  37.  
  38. Console.WriteLine("---- echo hello world ----")
  39. Console.WriteLine(strOutput)
  40.  
  41. strOutput = ssh.QuickCommand("date","ansi")
  42. If (ssh.LastMethodSuccess <> True) Then
  43.     Console.WriteLine(ssh.LastErrorText)
  44.     Exit Sub
  45. End If
  46.  
  47. Console.WriteLine("---- date ----")
  48. Console.WriteLine(strOutput)
  49.  
  50. '  --------------
  51. '  Sample output:
  52.  
  53. '   ---- df ----
  54. '   Filesystem    512-blocks      Used  Available Capacity  iused     ifree %iused  Mounted on
  55. '   /dev/disk2    2176716032 265736304 1910467728    13% 33281036 238808466   12%   /
  56. '   devfs                382       382          0   100%      662         0  100%   /dev
  57. '   map -hosts             0         0          0   100%        0         0  100%   /net
  58. '   map auto_home          0         0          0   100%        0         0  100%   /home
  59. '   /dev/disk3s2      374668    374668          0   100%    93665         0  100%   /Volumes/Google Chrome
  60. '
  61. '   ---- echo hello world ----
  62. '   hello world
  63. '
  64. '   ---- date ----
  65. '   Thu Dec 22 17:19:32 CST 2016
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement