是否存在可以将文件上载到SFTP(SSH FTP)服务器的免费.NET库,该服务器会抛出上载问题的异常并允许监视其进度?
以下代码显示了如何使用我们的Rebex SFTP组件将文件上载到SFTP服务器.
// create client, connect and log in
Sftp client = new Sftp();
client.Connect(hostname);
client.Login(username, password);
// upload the 'test.zip' file to the current directory at the server
client.PutFile(@"c:\data\test.zip", "test.zip");
client.Disconnect();
Run Code Online (Sandbox Code Playgroud)
您可以使用LogWriter属性将完整的通信日志写入文件,如下所示.可以在此处找到示例输出(来自FTP组件,但SFTP输出类似).
client.LogWriter = new Rebex.FileLogWriter(
@"c:\temp\log.txt", Rebex.LogLevel.Debug);
Run Code Online (Sandbox Code Playgroud)
或使用以下事件拦截通信:
Sftp client = new Sftp();
client.CommandSent += new SftpCommandSentEventHandler(client_CommandSent);
client.ResponseRead += new SftpResponseReadEventHandler(client_ResponseRead);
client.Connect("sftp.example.org");
//...
private void client_CommandSent(object sender, SftpCommandSentEventArgs e)
{
Console.WriteLine("Command: {0}", e.Command);
}
private void client_ResponseRead(object sender, SftpResponseReadEventArgs e)
{
Console.WriteLine("Response: {0}", e.Response);
}
Run Code Online (Sandbox Code Playgroud)
.net 框架内没有解决方案。
http://www.eldos.com/sbb/sftpcompare.php概述了非自由选项的列表。
最好的免费选择是使用 Granados 扩展 SSH。http://www.routerk.co.jp/en/product/varaterm/granados.html