Is there any way PGP can encrypt a data stream and save it directly to FTP without saving it locally?

I need to send an encrypted PGP file in asc format to an FTP folder via sFTP. Is there a way to PGP-encrypt a stream (which is a stream in CSV format) and push it to sFTP without storing it on the local computer .

Below is the function that I use for PGP encryption, which takes the file name as param:

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 

Again, the basic requirement is not to save the encrypted PGP file locally and then send it to FTP, but the encrypted PGP file must be created through the stream.

Any ideas?

UPDATE:

FTP code:

  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 is System.IO.Stream.

+4
source share
1 answer

Instead of entering the file name as an option on the command line, you can pass - to --output , which directly outputs the output to the console. You can directly transfer this data.

The Arguments property will look like this:

 psi.Arguments = String.Format(" --armor --yes --recipient ""{0}"" --output - --encrypt ""{1}""", _ pgpRecipient, FileName) 

When you execute the process, ProcessPGP.StandardOutput should provide the necessary thread.

0
source

All Articles