EldoS
Home / SecureBlackbox® / SecureBlackbox® - Completely managed SFTP components for .NET framework (SFTP C#, SFTP .NET, SFTP VB .NET, SFTP C++ .NET, SFTP ASP .NET)
SITE SEARCH
Advanced search
SOLUTION GUIDE
For Software Developers
For Business Integrators
PRODUCT LINES
BizCrypto
SecureBlackbox
Callback File System
CallbackFilter
CallbackDisk
SolFS (Solid File System)
RawDisk
MsgConnect
VoxPopuli
Crypto4
Custom services
NEED HELP?
Support options
Knowledgebase
Forums
HelpDesk
CUSTOMER RELATIONS
Testimonials
Geography
Contact Us
My Control Center
COMPANY INFORMATION
Company news
Corporate information
For investors
For press
For partners

Use SFTPBlackbox from Visual Basic .NET to upload and download files via SFTP (SSH File Transfer Protocol)

SFTP protocol is a part of SSH family of protocols. Nowadays SFTP has become a de-facto standard for secure transfer of files between Web servers. As .NET Framework doesn't include support for SSH and SFTP protocols, EldoS Corporation offers a powerful solution - SFTPBlackbox (.NET edition).

SFTPBlackbox makes file operations via SFTP on .NET platform as easy as 1-2-3. The code below is the complete console application, which can be used to upload and download files and list the directories. As you can see, the SFTP calls fit into just about a dozen of lines of code. The rest of code parses command-line parameters.

To see what outstanding features make SFTPBlackbox an optimal choice, see Description of SFTPBlackbox.NET or check the comparison chart of SFTP solutions for .NET

Download SecureBlackbox from the Download page.

Before you start

  • Check that you have an SSH server to test, and this SSH server has SFTP subsystem enabled. Alternatively, some FTP servers support SFTP protocol. If you don't have an SSH server...
  • Install SecureBlackbox .NET (you can download it from the Download page). If you plan to run the sample on the server, please read the deployment instructions in SecureBlackbox help file.

Source code

    
    
  1. Imports SBUtils
  2. Imports SBSftpCommon
  3. Imports SBSimpleSftp
  4. Module ConsoleSftpClient
  5. Dim Client As TElSimpleSFTPClient
  6. ' command line parameters
  7. Const OP_LIST As Integer = 1
  8. Const OP_DOWNLOAD As Integer = 2
  9. Const OP_UPLOAD As Integer = 3
  10. Dim parOperation As Integer = 0
  11. Dim parRemoteName As String = "/"
  12. Dim parLocalName As String
  13. Dim parUsername As String
  14. Dim parPassword As String
  15. Dim parAddress As String
  16. Dim parPort As Integer = 22
  17. Sub Download()
  18. ' Download the file from SFTP server and optionally overwrite local file if it exists
  19. Client.DownloadFile(parRemoteName, parLocalName, TSBSFTPFileTransferMode.ftmOverwrite)
  20. End Sub
  21. Sub Upload()
  22. ' Upload the file to SFTP server and optionally overwrite remote file if it exists
  23. Client.UploadFile(parLocalName, parRemoteName, TSBSFTPFileTransferMode.ftmOverwrite)
  24. End Sub
  25. Sub List()
  26. Dim Handle As Byte()
  27. Dim AListing As ArrayList
  28. ' Read the directory contents to AListing
  29. Handle = Client.OpenDirectory(parRemoteName)
  30. Try
  31. AListing = New ArrayList
  32. Client.ReadDirectory(Handle, AListing)
  33. Finally
  34. Client.CloseHandle(Handle)
  35. End Try
  36. ' List the contents
  37. If AListing.Count > 0 Then
  38. System.Console.WriteLine("Contents of " + parRemoteName + ":")
  39. Dim i As Integer
  40. For i = 0 To AListing.Count - 1
  41. ' we only write file names
  42. ' but it's possible to write other data such as date and attributes
  43. System.Console.WriteLine(CType(AListing(i), TElSftpFileInfo).Name)
  44. Next i
  45. Else
  46. System.Console.WriteLine("The specified directory is empty")
  47. End If
  48. End Sub
  49. Sub Main()
  50. ' set the license key. Trial license key is specified below.
  51. ' Trial key causes SecureBlackbox work slower.
  52. ' Request time-limited license key without delays on http://www.eldos.com/sbb/keyreq/
  53. SBUtils.Unit.SetLicenseKey("0190B807FC3C84EE4CAE3222EA8EBCC503B55E8ADEF669" _
  54. & "3234E36786EB2D9D4FC7AE8D79E5FAF39B757F24D91612EB46AB96F54B154B88E5DC3F1" _
  55. & "E17B9A1F4C9DC47ED662B1C088FD381213252B7633FFEC2D4D88DE70415BC9F89403D1D" _
  56. & "49A26E8279017526C44AFE15A6B2F707F60A984E25E7A8AFA6ABE01DFB9A7DC12A20B82" _
  57. & "ACB542145733EC394913AB6966604BA3ED0FEE2145667889094BC993B33E11648552AF6" _
  58. & "D8574D751BF22CE5BE648EFF26A3B0B785B95F0C5A8C239F567FAA19FB293E3EFAA0A7D1" _
  59. & "7D58EE9295841A0FD08EBCA3A74580C338F6F614833F3C00CD217E4B74977070AA6D3783" _
  60. & "1EA712542B7784481C178E0789F29BC749773A")
  61. ' Parse the command line parameters
  62. If Not ParseCommandLine() Then
  63. Return
  64. End If
  65. ' create SFTP client component
  66. Client = New TElSimpleSFTPClient
  67. ' set connection parameters
  68. Client.Address = parAddress
  69. Client.Port = parPort
  70. Client.Username = parUsername
  71. Client.Password = parPassword
  72. ' Perform the operation
  73. Try
  74. ' Connect to the SFTP server
  75. Client.Open()
  76. Try
  77. Select Case parOperation
  78. Case OP_DOWNLOAD
  79. Download()
  80. Exit Select
  81. Case OP_UPLOAD
  82. Upload()
  83. Exit Select
  84. Case OP_LIST
  85. List()
  86. Exit Select
  87. End Select
  88. Finally
  89. ' Disconnect from the SFTP server
  90. Client.Close(False)
  91. End Try
  92. Catch ex As Exception
  93. System.Console.WriteLine(ex.Message)
  94. End Try
  95. End Sub
  96. Function ParseCommandLine() As Boolean
  97. Dim Args As String()
  98. Args = Environment.GetCommandLineArgs
  99. Dim arg As String
  100. Dim i As Integer = 1
  101. If (Args.Length = 1) Then
  102. ParseCommandLine = False
  103. Exit Function
  104. End If
  105. While i < Args.Length
  106. arg = Args(i)
  107. Select Case arg
  108. Case "-down", "-download"
  109. parOperation = OP_DOWNLOAD
  110. Exit Select
  111. Case "-up", "-upload"
  112. parOperation = OP_UPLOAD
  113. Exit Select
  114. Case "-list"
  115. parOperation = OP_LIST
  116. Exit Select
  117. Case "-addr", "-address"
  118. i = i + 1
  119. parAddress = Args(i)
  120. Exit Select
  121. Case "-port"
  122. i = i + 1
  123. Try
  124. parPort = Int32.Parse(Args(i))
  125. Catch
  126. parPort = 22
  127. End Try
  128. Exit Select
  129. Case "-user", "-username"
  130. i = i + 1
  131. parUsername = Args(i)
  132. Exit Select
  133. Case "-pass", "-password"
  134. i = i + 1
  135. parPassword = Args(i)
  136. Exit Select
  137. Case "-local"
  138. i = i + 1
  139. parLocalName = Args(i)
  140. Exit Select
  141. Case "-remote"
  142. i = i + 1
  143. parRemoteName = Args(i)
  144. Exit Select
  145. End Select
  146. i = i + 1
  147. End While
  148. ParseCommandLine = parOperation <> 0
  149. End Function
  150. End Module

Feel free to use this sample in your C# or VB.NET applications, that use SFTP. The console SFTP sample is available for C# and VB.NET. It's included into SecureBlackbox 5.1 and is also available as a separate download.

SFTPBlackbox can be used separately or in one cost-saving SecureBlackbox package. You can use SecureBlackbox with any .NET development tool that supports .NET Framework (1.1, 2.0, 3.0, 3.5), .NET CF (Compact Framework) (1.0 or 2.0) or Mono (1.0 or 2.0) including Visual Studio 2008, Visual Studio 2005, Visual Studio .NET 2003, Borland Delphi 8, Delphi 2005, 2006 and 2007, Borland C# Builder

Read more about SFTPBlackbox .NET.

Download SecureBlackbox from the Download page.

Most wanted features
Vote or request a feature
Support and Resources
  • Knowledgebase
  • Documentation on-line
  • Forum
  • Ask a question in HelpDesk
Latest version

8.0.176
Released 23 May 2010

  • New And Improved Features
  • Change list
  • Download
Contact Us | Terms of Use | Trademarks | Privacy Statement | Site Index
Copyright (c) 1998-2010, EldoS Corporation
Design by Web Arsenal