使用WebClient.UploadFile与TLS(1.1或1.2)

huangapple go评论113阅读模式
英文:

Using WebClient.UploadFile with TLS (1.1 or 1.2)

问题

只想知道WebClient.UploadFile是否通过1.1或1.2来进行TLS安全传输。我找到了以下代码行并已安装在我的应用程序中。

System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;

以下代码行在我的应用程序中工作。

WebClient.UploadFile("ftp://xxx.xxxx.xxx/xxxx/xxxx/" + Path.GetFileName(file), file);

这里有没有测试安全性的方法?

英文:

Just wondering if WebClient.Uploadfile is TLS secure either by 1.1 or 1.2. I found the following line of code and have installed in my application.

System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;

The following line of code does the work in my application

WebClient.UploadFile("ftp://xxx.xxxx.xxx/xxxx/xxxx/" + Path.GetFileName(file), file);

Is there any way to test for security here?

答案1

得分: 1

你可以使用优秀的 WinSCP 库(程序集源代码)来建立安全的FTP连接:

using var session = new Session();
session.Open(new SessionOptions
{
    Protocol = Protocol.Ftp,
    HostName = "ftp.example.com",
    UserName = "username",
    Password = "password",
    FtpSecure = FtpSecure.Explicit,
    TlsHostCertificateFingerprint = "xx:xx:xx:..."
});
session.PutFiles("本地路径", "远程路径").Check();

你可以通过 FtpSecure 设置TLS是否应该是显式或隐式的。隐式TLS需要不同的端口,而显式TLS允许在同一端口上使用非安全和安全连接。

英文:

You can use nice WinSCP library (assemblies source) for secure FTP connection:

using var session = new Session();
session.Open(new SessionOptions
{
    Protocol = Protocol.Ftp,
    HostName = "ftp.example.com",
    UserName = "username",
    Password = "password",
    FtpSecure = FtpSecure.Explicit,
    TlsHostCertificateFingerprint = "xx:xx:xx:...",
});
session.PutFiles("local path", "remote path").Check();

You can set by FtpSecure, if TLS should be explicit or implicit. Implicit TLS requires different port, while explicit TLS gives possibility to use the same port for unsecure and secure connection.

答案2

得分: 0

WebClient.UploadFile 不安全。设置 ServicePointManager.SecurityProtocol 不会改变这一点。

请参阅 https://stackoverflow.com/q/4331665/850848

英文:

WebClient.UploadFile is not secure. Setting ServicePointManager.SecurityProtocol does not change anything about it.

See https://stackoverflow.com/q/4331665/850848.

huangapple
  • 本文由 发表于 2023年7月23日 19:56:59
  • 转载请务必保留本文链接:https://go.coder-hub.com/76748106.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定