【发布时间】:2013-02-16 03:31:22
【问题描述】:
我必须通过 sFTP 将 asc 格式的 PGP 加密文件发送到 FTP 文件夹。有没有办法 PGP 加密流(这是 CSV 格式的流)并将其推送到 sFTP而无需将其保存在本地机器上。
下面是我用于PGP加密的函数,它以文件名为参数:
Private Function PGPEncrypt(ByVal FileName As String) As Boolean
Dim errorHappened As Boolean = False
Dim encodedFileName As String = String.Format("{0}{1}", FileName, ".asc")
Dim pgpRecipient As String = System.Configuration.ConfigurationManager.AppSettings.Get("PgpRecipient")
Dim psi As System.Diagnostics.ProcessStartInfo
Dim ErrorResult As String = ""
Dim Result As String = ""
Try
psi = New ProcessStartInfo(System.Configuration.ConfigurationManager.AppSettings.Get("PgpPath"))
psi.CreateNoWindow = True
psi.UseShellExecute = False
psi.Arguments = String.Format(" --armor --yes --recipient ""{0}"" --output ""{1}"" --encrypt ""{2}""", _
pgpRecipient, encodedFileName, FileName)
psi.RedirectStandardInput = True
psi.RedirectStandardOutput = True
psi.RedirectStandardError = True
ProcessPGP = System.Diagnostics.Process.Start(psi)
ProcessPGP.StandardInput.Write(m_Passphrase)
Result = ProcessPGP.StandardError.ReadToEnd()
ProcessPGP.WaitForExit()
Catch ex As Exception
errorHappened = True
Dim ReadError As New StringBuilder()
ReadError.Append(vbCrLf & "Error Detail:")
ReadError.Append(vbCrLf & ex.ToString())
OurEventLog.WriteEntry(ReadError.ToString(), EventLogEntryType.Error)
End Try
Return errorHappened
End Function
同样,主要要求是不将 PGP 加密文件保存在本地,然后发送到 FTP,但必须通过流创建 PGP 加密文件。
有什么想法吗?
更新:
FTP 代码:
ftp.ConnectMode = FTPConnectMode.PASV
ftp.RemoteHost = Csla.ConfigurationManager.AppSettings("FTPRemoteHost")
If _blnDiagnostics Then DiagnosticsManager.Publish("STREAM_TO_FTP: CONNECT TO FTP", DiagnosticsManager.EntryType.SuccessAudit)
ftp.Connect()
ftp.Login(strUser, strPassword)
ftp.TransferType = FTPTransferType.BINARY 'ASCII
ftp.Put(OUTBOUNDMESSAGE, pFilename)
ftp.Quit()
ftp = Nothing
OUTBOUNDMESSAGE 是 System.IO.Stream。
【问题讨论】:
-
这在我看来不像 C#...?
标签: vb.net encryption sftp pgp