Upload 2 Files with different names (no wildcards)

Advertisement

Maikl
Joined:
Posts:
1
Location:
Austria

Upload 2 Files with different names (no wildcards)

Hi,

my problem is this: I have to upload 2 files with different names. One file is created by MS SQL Reporting Services, let's call it Export.csv. The other is created by a Powershell script and contains the MD5 Hash of the first file. Let's call it Hash.txt.

Now I have to upload them and give them a different name (adding a timestamp to the file name). What I have done so far is:

[...]
$transferOptions = New-Object WinSCP.TransferOptions
$transferOptions.TransferMode = [WinSCP.TransferMode]::Binary

$transferResult = $session.PutFiles("C:\PathTo\Export.csv", "Export$(Get-Date -format yyMMddhhmm).csv", $False, $transferOptions)
$transferResult.Check()

$transferResult = $session.PutFiles("C:\PathTo\Hash.txt", "Hash$(Get-Date -format yyMMddhhmm).txt", $False, $transferOptions)
$transferResult.Check()
[...]

This works so far.

My question is: Is there a way to upload these two files in one step, something like

[...]
$files2upload = @("C:\PathTo\Export.csv", "C:\PathTo\Hash.txt")
$renamedFiles = @()

foreach($file2upload in $files2upload)
{
    $fileInfo = [io.FileInfo] $file2upload
    $renamedFiles += ("{0}{1}{2}" -f $fileInfo.BaseName, $(Get-Date -format yyMMddhhmm), $fileInfo.Extension)
}

$transferResult = $session.PutFiles($files2Upload, $renamedFiles, $False, $transferOptions)
[...]

Thanks for your help!
Michael

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
40,476
Location:
Prague, Czechia

Re: Upload 2 Files with different names (no wildcards)

Maikl wrote:

My question is: Is there a way to upload these two files in one step, something like
Why? What do you expect from that?

Reply with quote

Advertisement

You can post new topics in this forum