Link to home
Start Free TrialLog in
Avatar of mesican
mesican

asked on

SFTP in vb.net

Is there a .NET class for SFTP (secure file transfer protocol)? I want to use vb.net to make a sftp conncetion but I cant find any information on it. Any suggestions?
Avatar of Éric Moreau
Éric Moreau
Flag of Canada image

Avatar of mesican
mesican

ASKER

Ya that cost $299.95. I found a way to do it for free though. You can use http://winscp.net/eng/index.php for SFTP. It has a great comand prompt for scripting and its free
ASKER CERTIFIED SOLUTION
Avatar of CetusMOD
CetusMOD
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
.NET Framework does not include SFTP support. You have to try a third party component. There is at least one free (called tamirgal) and a few commercial. Following code is taken from samples of Rebex SFTP for .NET (http://www.rebex.net/sftp.net/)

https://www.rebex.net/sftp.net/tutorial-sftp.aspx#upload-download

'create client, connect and log in
Dim client As New SFtp
client.Connect("sftp.example.org")
client.Login("username", "password")

' upload the 'test.zip' file to the current directory at the server
client.PutFile("c:\data\test.zip", "test.zip")

' upload the 'index.html' file to the specified directory at the server
client.PutFile("c:\data\index.html", "/wwwroot/index.html")

' download the 'test.zip' file from the current directory at the server
client.GetFile("test.zip", "c:\data\test.zip")

' download the 'index.html' file from the specified directory at the server
client.GetFile("/wwwroot/index.html", "c:\data\index.html")

' upload a text using a MemoryStream
Dim message As String = "Hello from Rebex SFTP for .NET!"
Dim data As Byte() = System.Text.Encoding.Default.GetBytes(message)
Dim ms As New System.IO.MemoryStream(data)
client.PutFile(ms, "message.txt")
Just for further details, there's a guide with VB.Net example for using WinSCP:
http://winscp.net/eng/docs/guide_dotnet