Подскажите как можно зашифровать файл и отправить его на ftp не сохраняя промежуточный результат на диск в Powershell?
Пока получилось так, но оно сохраняет промежуточный результат, надо чтобы лилось сразу на ftp.
Спасибо.
$str = "'C:\Program Files\OpenSSL\bin\openssl.exe' enc -e -aes-256-cbc -a -in '" + $file.Fullname + "' -out '" + $encrDest + $file + ".enc' -k 'key'"
Invoke-Expression "& $str"
Add-Type -Path "C:\Scripts\WinSCPnet.dll"
# Setup session options
$sessionOptions = New-Object WinSCP.SessionOptions -Property @{
Protocol = [WinSCP.Protocol]::Ftp
HostName = "7.7.7.7"
UserName = "user"
Password = "pass"
}
try
{
# Connect
$session = New-Object WinSCP.Session
$session.Open($sessionOptions)
# List files
$remotePath = "/"
$directoryInfo = $session.ListDirectory($remotePath)
# Find old files
$limit = (Get-Date).AddDays(-1)
$oldFiles =
$directoryInfo.Files |
#Where-Object { -Not $_.IsDirectory } |
Where-Object { $_.LastWriteTime -lt $limit }
$oldFiles
# Delete them
foreach ($oldFileInfo in $oldFiles)
{
if ($oldFileInfo.Name -ne '..') {
$oldFilePath = $session.EscapeFileMask($remotePath + "/" + $oldFileInfo.Name)
$session.RemoveFiles($oldFilePath).Check()
}
}
# Upload files
$transferOptions = New-Object WinSCP.TransferOptions
$transferOptions.TransferMode = [WinSCP.TransferMode]::Binary
$transferResult = $session.PutFiles($encrDest, "/", $False, $transferOptions)
# Throw on any error
$transferResult.Check()
# Print results
foreach ($transfer in $transferResult.Transfers)
{
Write-Host ("Upload of {0} succeeded" -f $transfer.FileName)
}
Write-Host "Done"
}
finally
{
# Disconnect, clean up
$session.Dispose()
}