Imports Renci.SshNet.SftpClient
.
.
.
Dim pa As New Renci.SshNet.PasswordAuthenticationMethod("<username for site>", "<password for site")
Dim connectionInfo As New Renci.SshNet.ConnectionInfo(ftpUrl, <site port number>, "<username for site>", Renci.SshNet.ProxyTypes.Socks5, "<our proxy name>", <our proxy port number>, "<my windows username>", "<my windows password", pa)
Dim sftp As New Renci.SshNet.SftpClient(connectionInfo)
sftp.Connect()
.
.
Comments: ** Comment from web user: mrinalk **
Hi,
I think I could read the file without downloading it. Please check following code. But now I have weird problem.
My requirement is to read more than one file. So I am calling following program in a loop. When I run the first time, it works fine, but for second call, it gives me "object reference not set" exception at sftpConnection.Connect() statement. Please help.
Dim pa As New Renci.SshNet.PasswordAuthenticationMethod(ConfigurationManager.AppSettings("SAndP.FtpUsername"), ConfigurationManager.AppSettings("SAndP.FtpPassword"))
Dim connectionInfo As New Renci.SshNet.ConnectionInfo(ConfigurationManager.AppSettings("SAndP.FtpUrl"), ConfigurationManager.AppSettings("SAndP.FtpPort"), ConfigurationManager.AppSettings("SAndP.FtpUsername"), Renci.SshNet.ProxyTypes.None, ConfigurationManager.AppSettings("ProxyHost"), ConfigurationManager.AppSettings("ProxySocks5Port"), ConfigurationManager.AppSettings("ProxySocks5Username"), ConfigurationManager.AppSettings("ProxySocks5Password"), pa)
Dim sftpConnection As New Renci.SshNet.SftpClient(connectionInfo)
sftpConnection.Connect()
If sftpConnection.IsConnected Then
If sftpConnection.Exists(strSrc) = False Then
sftpConnection.Disconnect()
sftpConnection.Dispose()
Return "not found"
End If
sModified = sftpConnection.GetLastWriteTime(strSrc).ToString()
Dim objReader As StreamReader = sftpConnection.OpenText(strSrc)
sCSV = objReader.ReadToEnd
sftpConnection.Disconnect()
sftpConnection.Dispose()
End If