I've written a service for our customer that automatically transmits files to given destinations using FTP. For historic reasons I'm using WinInet to perform the FTPing. All works well, but now the customer wants to add one destination that only accepts SFTP connections.
我为我们的客户编写了一个服务,该服务使用FTP自动将文件传输到给定的目的地。出于历史原因,我使用WinInet来执行FTPing。所有功能都很好,但是现在客户希望添加一个只接受SFTP连接的目的地。
I do not really like the idea of implementing this from scratch, so is there a way to communicate natively or through WinInet with a SFTP server? Are there any system libraries that I can use (I have no fear of P/Invoke :) )? Do I have to purchase third party components for that - if so, which ones would you suggest?
我不太喜欢从头开始实现这个想法,那么是否有一种方法可以通过WinInet与SFTP服务器进行本地通信?是否有我可以使用的系统库(我不害怕P/Invoke:) ?我需要购买第三方组件吗?如果需要,您建议购买哪些?
7 个解决方案
#1
1
Unfortunately, SFTP is not natively supported by WinInet or any other standard Windows libraries.
不幸的是,WinInet或其他任何标准Windows库都不支持SFTP。
I've had good luck with /n Software's IP*Works SSH for .NET in talking to a large variety of SFTP servers.
我很幸运地使用了/n软件的IP*为。net运行SSH,与各种SFTP服务器进行通信。
#2
4
There's no support for SFTP in .NET framework, in any version.
在。net framework中,任何版本都不支持SFTP。
You have to use a third party library for SFTP.
您必须为SFTP使用第三方库。
You can use WinSCP .NET assembly. There's even a WinSCP NuGet package.
可以使用WinSCP . net程序集。甚至还有WinSCP NuGet包。
A trivial SFTP upload C# example:
一个简单的SFTP上传c#示例:
// Setup session options
SessionOptions sessionOptions = new SessionOptions
{
Protocol = Protocol.Sftp,
HostName = "example.com",
UserName = "user",
Password = "mypassword",
SshHostKeyFingerprint = "ssh-rsa 2048 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx"
};
using (Session session = new Session())
{
// Connect
session.Open(sessionOptions);
// Upload files
session.PutFiles(@"d:\toupload\*", "/home/user/").Check();
}
There are lot of other examples.
还有很多其他的例子。
You can have WinSCP GUI generate an SFTP code template, like above, for you, including C#, VB.NET and PowerShell.
您可以让WinSCP GUI为您生成一个SFTP代码模板,如上面所示,包括c#、VB。净,PowerShell。
The assembly is just a wrapper around WinSCP scripting, so it's not a completely native .NET code. As such it does not fit all use cases in .NET framework. It is mostly suitable for automating tasks, not for developing GUI or web applications.
这个程序集只是WinSCP脚本的一个包装器,所以它不是一个完全的。net代码。因此,它不适合。net框架中的所有用例。它主要适用于自动化任务,而不适用于开发GUI或web应用程序。
For a fully native .NET SFTP library, see SSH.NET, which is strangely not mentioned in any answer yet.
对于一个完全本机的。net SFTP库,请参见SSH。奇怪的是,在任何回答中都没有提及。
(I'm the author of WinSCP)
(我是WinSCP的作者)
#3
0
the .NET Framwork supports FTP via the FtpWebRequest since version 2.0. No support for SFTP yet.
自2.0版本以来,. net框架通过FtpWebRequest支持FTP。还没有对SFTP的支持。
If you need both FTP and SFTP you have to try a third party component. There is an open source implementation of SFTP from Tamir Gal which is often recommended. Or you can try one of commercial SFTP components such as our Rebex SFTP.
如果您同时需要FTP和SFTP,您必须尝试第三方组件。有一个来自Tamir Gal的SFTP的开源实现,这是经常被推荐的。或者您可以尝试一个商业SFTP组件,比如我们的Rebex SFTP。
Following code is taken from Rebex SFTP tutorial page:
以下代码取自Rebex SFTP教程页面:
// create client, connect and log in
Sftp client = new Sftp();
client.Connect(hostname);
client.Login(username, password);
// upload the content of 'c:\data' directory and all subdirectories
// to the '/wwwroot' directory at the server
client.PutFiles(@"c:\data\*", "/wwwroot", SftpBatchTransferOptions.Recursive);
client.Disconnect();
If you are not sure whether you will need FTPS or SFTP you can check the Rebex File Transfer Pack which includes both. The FTP API is almost identical to the SFTP one.
如果您不确定是否需要FTPS或SFTP,您可以检查Rebex文件传输包,其中包括这两个文件。FTP API几乎与SFTP API相同。
#4
0
JFYI: probably the most feature-rich components for SFTP in .NET is our SFTPBlackbox.
JFYI:可能。net中SFTP最富特性的组件是SFTPBlackbox。
#5
0
http://sourceforge.net/projects/sharpssh/ could be your best best. I ended up writing scripts for WinSCP though, which was easier...
http://sourceforge.net/projects/sharpssh/可能是你最好的。最后我为WinSCP编写了脚本,这更容易……
EDIT for clarity, I'd recommend something like https://github.com/sshnet/SSH.NET now as SharpSSH is a dead project
为了清晰起见,我建议您使用https://github.com/sshnet/SSH.NET,因为SharpSSH是一个已死的项目。
#6
0
I created a demo of interactions with SFTP server using WinSCP.
我使用WinSCP创建了一个与SFTP服务器交互的演示。
This application is able to upload, delete, rename and fetch info of files system in an SFTP Server using WinSCP .NET Assembly.
这个应用程序可以使用WinSCP . net程序集在SFTP服务器上上传、删除、重命名和获取文件系统的信息。
Take a look at: https://github.com/ducfilan/SFTP-with-WinSCP
看看:https://github.com/ducfilan/SFTP-with-WinSCP
#7
-1
I use edtFTPnet/PRO
我使用edtFTPnet / PRO
http://www.enterprisedt.com/products/edtftpnetpro/overview.html
http://www.enterprisedt.com/products/edtftpnetpro/overview.html
works great
伟大的工作
#1
1
Unfortunately, SFTP is not natively supported by WinInet or any other standard Windows libraries.
不幸的是,WinInet或其他任何标准Windows库都不支持SFTP。
I've had good luck with /n Software's IP*Works SSH for .NET in talking to a large variety of SFTP servers.
我很幸运地使用了/n软件的IP*为。net运行SSH,与各种SFTP服务器进行通信。
#2
4
There's no support for SFTP in .NET framework, in any version.
在。net framework中,任何版本都不支持SFTP。
You have to use a third party library for SFTP.
您必须为SFTP使用第三方库。
You can use WinSCP .NET assembly. There's even a WinSCP NuGet package.
可以使用WinSCP . net程序集。甚至还有WinSCP NuGet包。
A trivial SFTP upload C# example:
一个简单的SFTP上传c#示例:
// Setup session options
SessionOptions sessionOptions = new SessionOptions
{
Protocol = Protocol.Sftp,
HostName = "example.com",
UserName = "user",
Password = "mypassword",
SshHostKeyFingerprint = "ssh-rsa 2048 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx"
};
using (Session session = new Session())
{
// Connect
session.Open(sessionOptions);
// Upload files
session.PutFiles(@"d:\toupload\*", "/home/user/").Check();
}
There are lot of other examples.
还有很多其他的例子。
You can have WinSCP GUI generate an SFTP code template, like above, for you, including C#, VB.NET and PowerShell.
您可以让WinSCP GUI为您生成一个SFTP代码模板,如上面所示,包括c#、VB。净,PowerShell。
The assembly is just a wrapper around WinSCP scripting, so it's not a completely native .NET code. As such it does not fit all use cases in .NET framework. It is mostly suitable for automating tasks, not for developing GUI or web applications.
这个程序集只是WinSCP脚本的一个包装器,所以它不是一个完全的。net代码。因此,它不适合。net框架中的所有用例。它主要适用于自动化任务,而不适用于开发GUI或web应用程序。
For a fully native .NET SFTP library, see SSH.NET, which is strangely not mentioned in any answer yet.
对于一个完全本机的。net SFTP库,请参见SSH。奇怪的是,在任何回答中都没有提及。
(I'm the author of WinSCP)
(我是WinSCP的作者)
#3
0
the .NET Framwork supports FTP via the FtpWebRequest since version 2.0. No support for SFTP yet.
自2.0版本以来,. net框架通过FtpWebRequest支持FTP。还没有对SFTP的支持。
If you need both FTP and SFTP you have to try a third party component. There is an open source implementation of SFTP from Tamir Gal which is often recommended. Or you can try one of commercial SFTP components such as our Rebex SFTP.
如果您同时需要FTP和SFTP,您必须尝试第三方组件。有一个来自Tamir Gal的SFTP的开源实现,这是经常被推荐的。或者您可以尝试一个商业SFTP组件,比如我们的Rebex SFTP。
Following code is taken from Rebex SFTP tutorial page:
以下代码取自Rebex SFTP教程页面:
// create client, connect and log in
Sftp client = new Sftp();
client.Connect(hostname);
client.Login(username, password);
// upload the content of 'c:\data' directory and all subdirectories
// to the '/wwwroot' directory at the server
client.PutFiles(@"c:\data\*", "/wwwroot", SftpBatchTransferOptions.Recursive);
client.Disconnect();
If you are not sure whether you will need FTPS or SFTP you can check the Rebex File Transfer Pack which includes both. The FTP API is almost identical to the SFTP one.
如果您不确定是否需要FTPS或SFTP,您可以检查Rebex文件传输包,其中包括这两个文件。FTP API几乎与SFTP API相同。
#4
0
JFYI: probably the most feature-rich components for SFTP in .NET is our SFTPBlackbox.
JFYI:可能。net中SFTP最富特性的组件是SFTPBlackbox。
#5
0
http://sourceforge.net/projects/sharpssh/ could be your best best. I ended up writing scripts for WinSCP though, which was easier...
http://sourceforge.net/projects/sharpssh/可能是你最好的。最后我为WinSCP编写了脚本,这更容易……
EDIT for clarity, I'd recommend something like https://github.com/sshnet/SSH.NET now as SharpSSH is a dead project
为了清晰起见,我建议您使用https://github.com/sshnet/SSH.NET,因为SharpSSH是一个已死的项目。
#6
0
I created a demo of interactions with SFTP server using WinSCP.
我使用WinSCP创建了一个与SFTP服务器交互的演示。
This application is able to upload, delete, rename and fetch info of files system in an SFTP Server using WinSCP .NET Assembly.
这个应用程序可以使用WinSCP . net程序集在SFTP服务器上上传、删除、重命名和获取文件系统的信息。
Take a look at: https://github.com/ducfilan/SFTP-with-WinSCP
看看:https://github.com/ducfilan/SFTP-with-WinSCP
#7
-1
I use edtFTPnet/PRO
我使用edtFTPnet / PRO
http://www.enterprisedt.com/products/edtftpnetpro/overview.html
http://www.enterprisedt.com/products/edtftpnetpro/overview.html
works great
伟大的工作