DestinationSubFolder

Hi,

I had the following path where files did get transferred Ok (Not ALL these files are within one Folder (EMISXMLExtract) in a server);

#Path on the remote system for the folder with collections in (unix style path)
$remotePath = “/XMLExtract”

#Sub folder used to hold newly fetched encrypted zips
$temporarySubfolder = "Temp"
#Sub folder used to hold decrypted uncompressed files
$unzipSubdirFolder = "ZipTemp"
#Output folder for fetched, decrypted, re-compressed files
$destinationSubfolder = "IncomingFiles"
#Sub directory with 7zip-extra in
$7zipSubdirFolder = "7z1602-extra"

Now, the destinationsubfolder location is now changed to another shared server with a different folder name as \xprdmdmed01\EmisInitialCollections\

Therefore, I changed the above code to;

#Path on the remote system for the folder with collections in (unix style path)
$remotePath = “/XMLExtract”

#Sub folder used to hold newly fetched encrypted zips
$temporarySubfolder = "Temp"
#Sub folder used to hold decrypted uncompressed files
$unzipSubdirFolder = "ZipTemp"
#Output folder for fetched, decrypted, re-compressed files
$destinationSubfolder = "\xprdmdmed01\EmisInitialCollections"
#Sub directory with 7zip-extra in
$7zipSubdirFolder = "7z1602-extra"

When I run the script the files did not transfer to \xprdmdmed01\EmisInitialCollections</strong>… Please any help…

Note: The server has been shared.

Thanks

Please share the part of your code where you actually copy the files. What you’ve provided so far are only variables with strings to folders.

Destination directories

	$temporaryTransferFolder = Join-Path $rootFolder $temporarySubfolder
	$destinationFolder = Join-Path $rootFolder $destinationSubfolder
	
	# Set transfer options to simple binary transfer, overwriting existing file
	# This is because we are handling abort resume ourselves
	$transferOptions = New-Object WinSCP.TransferOptions -Property @{
		TransferMode = [WinSCP.TransferMode]::Binary
		ResumeSupport = New-Object WinSCP.TransferResumeSupport -Property @{
			State  = [WinSCP.TransferResumeSupportState]::Off
		}
		OverwriteMode = [WinSCP.OverwriteMode]::Overwrite
	}
	
	foreach ($remoteFile in $collectionFiles) {
		Write-Host "Retrieving " $remoteFile.Name
		
		#Determine path to remot file
		$remoteFilePath = $remotePath + "/" + $remoteFile.Name
		$localTempFilePath = Join-Path $temporaryTransferFolder $remoteFile.Name
		
		#Fetch the file
		$session.GetFiles($session.EscapeFileMask($remoteFilePath), $localTempFilePath).Check()
		
		#Verify transfer with checksum
		$remoteChecksum = [System.BitConverter]::ToString($session.CalculateFileChecksum("sha-1", $remoteFilePath))
		$sha1 = [System.Security.Cryptography.SHA1]::Create()
		$localChecksum = "NotYetSetNotNull"
		try {
			$localStream = [System.IO.File]::OpenRead($localTempFilePath)
			$localChecksum = [System.BitConverter]::ToString($sha1.ComputeHash($localStream))
		}
		finally
		{
			$localStream.close()
		}
		#If retrieved file different from original, throw and quit for retrieval next run
		if (-not $localChecksum -eq $remoteChecksum) {
			throw [System.IO.InvalidDataException] "Checksums do not match, transfer corrupted"				
		}			
		
		#Delete the original from the remote server
		#$session.RemoveFiles($session.EscapeFileMask($remoteFilePath)).Check()			
		
		# Asyncrhonously decrypt and re zip the incoming files
		Start-Job -FilePath $DecryptAndReZipScript -ArgumentList $7zipFolderFullPath, $unzipFolderFullPath, $localTempFilePath, $destinationFolder, $zipPassword
		
		#If there are more than 10 jobs running, wait till one finishes before starting the next
		while((Get-Job -State 'Running').Count -ge 10)
		{
			Start-Sleep -Milliseconds 10
		}
		
		Write-Host "Sucessfully fetched " $remoteFile.Nameasync
	}
     
}
finally
{
    # Disconnect, clean up
    $session.Dispose()
}

exit 0

}
catch [Exception]
{
Write-Host (“Error: {0}” -f $_.Exception.Message)
exit 1
}

Thanks for posting the code.

If you replace

$destinationFolder = Join-Path $rootFolder $destinationSubfolder

with

$destinationFolder = "\xprdmdmed01\EmisInitialCollections"

it should work as expected.