Using $session.MoveFile
Hello,
I need to write a PowerShell script to download some files of remote Unix server and after download I want to archive files in
The download works perfectly but the archive using
This is my code:
My SMA Opcon job is failed but I don't have any errors appears.
I have tried some syntax but I despair.
It's probably nothing at all but I can't find a solution.
Have you some idea?
Kind Regards,
Mitakue
I need to write a PowerShell script to download some files of remote Unix server and after download I want to archive files in
Archive
folder.
The download works perfectly but the archive using
$Session.MoveFile
doesn't work.
This is my code:
$fileInfos = $session.EnumerateRemoteFiles($InputDir, $FilePattern, [WinSCP.EnumerationOptions]::MatchDirectories) if ($fileInfos.Count -gt 0) { foreach ($fileInfo in $fileInfos) { Write-host("`r------ Action --------------------`r") # Download files $transferResult = $session.GetFiles($fileInfo.FullName, "$OutputDir\", $False, $transferOptions) # Test file not Found if ($($transferResult.Transfers.count) -ne 0) { #"[$todaylog] - [Action] $Action Transfer $filesCount files on $($transferResult.Transfers.count) : $($FileInfo.Name)" >> $LogFile Write-host("$todaylog Download $filesCount file(s) : $($FileInfo.Name)") $filesCount=$filesCount+1 $file = $OutputDir+ "\" + $fileInfo.Name $separator = "." $parts = $fileInfo.Name.Split($separator) $file_basename = $parts[0] $file_extension = "." + $parts[1] #Destination de l'archive $DestinationFile = $ArchiveDir + "\" + $file_basename + "_" + $todayDate + $file_extension #Taille du Fichier $filesize=[math]::Round($($file.length / 1kb),2) #Comptage des lignes du fichier $lines = (get-content $file | measure-object -line).lines #$session.MoveFile($FilePattern, $DestinationFile) foreach ($transfer in $transferResult.Transfers) { # Success or error? if ($transfer.Error -eq $Null) { Write-Host " $InputDir/$fileInfo " Write-Host "Upload of $($transfer.FileName) succeeded, moving to backup" # Upload succeeded, move source file to backup $session.MoveFile(("$InputDir/$fileInfo", $ArchiveDir)).Check() } else { Write-Host "Upload of $($transfer.FileName) failed: $($transfer.Error.Message)" } }
I have tried some syntax but I despair.
It's probably nothing at all but I can't find a solution.
Have you some idea?
Kind Regards,
Mitakue