#freeze
[[FrontPage]]
これ、わたしはあまり使わないから最低限の検証しかしてないの。
でも、2015年にも更新があるみたいで、使えるライブラリだと思うわ。
* 組み込み方 [#o99342d9]
下の参考リンクから最新版をとりよせて。ZIPだから解凍するとバイナリが出てくるわ。
で、出てきたDLLを参照設定で追加すれば使えるわ。
* 参考コード [#x81e90bf]
using Renci.SshNet;
:
:
/// <summary>
/// This sample will download a file on the remote system to your local machine.
/// </summary>
private static string uploadFile(string host, string username, string password, string remoteFileName, string localFileName)
{
string r = null;
Console.WriteLine("1");
try
{
using (var sftp = new SftpClient(host, username, password))
{
Console.WriteLine("2");
sftp.Connect();
DateTime ltm = File.GetLastWriteTime(localFileName);
using (var file = File.OpenRead(localFileName))
{
Console.WriteLine("3");
//FileStream sinn = new FileStream(localFileName, FileMode.Open);
sftp.UploadFile(file, remoteFileName,true); // true/false: can overwrite
//sftp.DownloadFile(remoteFileName, file);
}
sftp.Disconnect();
}
}
catch (Exception ex)
{
Console.WriteLine("転送時のエラー発生");
r = ex.Message;
Console.WriteLine(r);
}
return (r);
}
* 参考リンク [#x09070fe]
- https://sshnet.codeplex.com/ SSH.NET
よくわかんないけど、SharpSSH(←すでに更新されてない古いライブラリ)にインスパイアされて、.NET4.0用に書いたものだって書いてあるわね。