【发布时间】:2023-03-15 12:10:01
【问题描述】:
我的任务是能够通过 FTPS 将文件发送到站点。这需要成为我生成要发送的文件的过程的一部分。我得到了一个程序(CoreFTP),它能够连接到该站点并且我可以查看/推送文件。我尝试通过使用 System.Diagnostics.Process 的 .Net 示例程序使用命令行到 CoreFTP,并将用户更改为导入证书的用户),但这没有用(没有错误,但没有文件服务器),所以我回到尝试使用 .NET 库连接到它。
我面临的问题是要连接到该站点,我必须连接到 AUTH TLS,并且它需要使用带有特定证书的 Windows TLS/SSL。
我发现这个例子 (https://www.limilabs.com/blog/use-ssl-with-ftp-explicit) 至少谈到了使用 AuthTLS,但是当我把它放在我的项目中时,它说 FTP 未定义。我尝试了建议的修复,但它们最终被破坏了(包括一个库,然后它说我需要实现 idisposable)。
我发现另一个网站 (https://support.microsoft.com/en-us/help/901183/how-to-call-a-web-service-by-using-a-client-certificate-for-authentica) 谈论获取特定证书,但我不知道如何将它与 FTP 一起使用。
因此,我对解决方案的偏好是: 1. .NET 解决方案不使用第三方库。 2. .NET 解决方案使用开源第三方库。 3. .NET 解决方案,我可以使命令行工作以使用 CoreFTP,我在与运行程序的用户不同的用户下运行命令行(因为证书/CoreFTP 配置文件是用户特定的)。 4. 使用我必须付费购买的库的 .NET 解决方案(真的希望不要推荐这个)。
这是(或多或少)我用来通过 .net 程序中的命令行命令运行 CoreFTP 的代码:
appname = "D:\Programs\coreftp.exe"
args = " -s -O -site Server_QA -u \\machine\docs\test.txt -p / " +
"-output \\machine\docs\corelog1.txt"
standOut = String.Empty
AddHandler objProcess.OutputDataReceived, AddressOf process_OutputDataReceived
' Start the Command and redirect the output
objProcess.StartInfo.UseShellExecute = False
objProcess.StartInfo.RedirectStandardOutput = True
objProcess.StartInfo.CreateNoWindow = True
objProcess.StartInfo.RedirectStandardError = True
objProcess.StartInfo.Domain = "mydomain"
objProcess.StartInfo.UserName = "administrator"
objProcess.StartInfo.Password = New System.Security.SecureString
For Each chr As Char In pwd.ToCharArray()
objProcess.StartInfo.Password.AppendChar(chr)
Next
objProcess.StartInfo.FileName() = AppName
If args.Length > 0 Then
objProcess.StartInfo.Arguments() = args
End If
objProcess.Start()
objProcess.BeginOutputReadLine()
objProcess.WaitForExit() 'Set to run for 20 minutes
If objProcess.HasExited() Then
'strOutput = objProcess.StandardOutput.ReadToEnd()
strOutput = standOut
strError = objProcess.StandardError.ReadToEnd()
If strOutput IsNot Nothing AndAlso strOutput.Length > 0 Then
PersonalDetailLog(strOutput)
End If
If strError IsNot Nothing AndAlso strError.Length > 0 Then
Throw New ApplicationException(strError)
End If
Else
PersonalDetailLog(
"The " + AppName + " Process has exceeded the 20 minute time out " +
"is is being closed")
If objProcess.Responding Then
objProcess.CloseMainWindow()
If Not objProcess.HasExited() Then
objProcess.Kill()
End If
Else
objProcess.Kill()
End If
Throw New ApplicationException("" + AppName + " Process Time Limit Exceeded.")
End If
【问题讨论】:
-
“带有特定证书的 Windows TLS/SSL” 有点含糊。是服务器证书还是客户端证书?