Hi guys,
I am struggling to connect SFTP SSH.net via key based connection.
I am storing key in a variable to use in code.
Below is the my code,
using Renci.SshNet.ScpClient;
using Renci.SshNet;
using System.Net;
using System.Collections.Generic;
using System.Text;
class Test_RunnableClass
{
public static void main(Args _args)
{
File fl;
System.Text.ASCIIEncoding encoding;
new InteropPermission(InteropKind::ClrInterop).assert();
var keyStr = @"-----BEGIN RSA PRIVATE KEY-----xyz-----END RSA PRIVATE KEY-----";
using (var keystrm = new System.IO.MemoryStream(encoding.GetBytes(keyStr)))
{
var privateKey = new PrivateKeyFile(keystrm);
using (var sftp = new Renci.SshNet.SftpClient(host, username, privateKey))
{
sftp.Connect();
sftp.ChangeDirectory(@"/MT940/HDFC Backup/");
var files = sftp.ListDirectory(@"/MT940/HDFC Backup/", null);
var enumerator = files.GetEnumerator();
while (enumerator.MoveNext())
{
var file = enumerator.current;
if ((file.Name != ".") && (file.Name != ".."))
{
info(file.name);
}
}
}
}
}
}
Can you pls help me on this.