This project is read-only.

Downloading problem

Jan 27, 2012 at 11:39 PM

Hi, I'm trying to use SSH.NET to download files from an SFTP site.  I'm using VB.NET, which I'm really not that familiar with, and I don't think I really understand how to code the .DownLoadFile method.  Either that or I don't understand the FileStream class.  The code below will connect to the site and list the files, but I'm getting this error on the DownloadFile method:

Value of type 'Renci.SshNet.Sftp.SftpFile' cannot be converted to 'String'.  

Here's the code:

            Dim oSFTP As Renci.SshNet.SftpClient
            Dim sFile As Renci.SshNet.Sftp.SftpFile
            Dim oOutput As System.IO.FileStream
            Dim sFileName As String
            Dim iFileNum As Integer

            oSFTP = New Renci.SshNet.SftpClient(sServer, sUsername, sPwd)

            sFileName = ""


            For Each sFile In oSFTP.ListDirectory(".\")

                'sFileName = sFileName & vbCrLf & sFile.Name
                sFileName = "e:\temp\FTPDL\" & sFile.Name
                oOutput = New System.IO.FileStream(sFileName, FileMode.Create)
                oSFTP.DownloadFile(sFile, oOutput)

                iFileNum = iFileNum + 1



            'GetSFTP = iFileNum.ToString & " Files Downloaded"

        Catch ex As Exception
            GetSFTP = ex.Message & vbCrLf & ex.ToString

        End Try

Can you tell me what I'm doing wrong?  Thanks.

Jan 28, 2012 at 1:38 PM

Your error has nothing to do with library.

You using sFile which is declared as SftpFile in DownloadFile method where it expects it as a string instead.


Jan 28, 2012 at 2:52 PM

Thanks Oleg, I should've figured that one out.  Guess I was tired.  It's working great now.