Running a script a 2nd time deletes the file
Hi all!
I'm trying to set up a very simple script to copy a file from a virtual machine to an Azure Web App. Due to some access issues, I've set the script to repeat the copy action 5 times, to ensure it gets copied. Problem is that when I run the script once, it copies the file. I run the script a 2nd time and it removes the file (on the destination).
This is the script:
Any help would be appreciated!
I'm trying to set up a very simple script to copy a file from a virtual machine to an Azure Web App. Due to some access issues, I've set the script to repeat the copy action 5 times, to ensure it gets copied. Problem is that when I run the script once, it copies the file. I run the script a 2nd time and it removes the file (on the destination).
This is the script:
# Load WinSCP .NET assembly Add-Type -Path "C:\WS\WinSCPnet.dll" $index = 0 $counter = 0 do { "Index Value: $index" $counter++ $index++ # Set up session options $sessionOptions = New-Object WinSCP.SessionOptions -Property @{ Protocol = [WinSCP.Protocol]::Ftp HostName = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" UserName = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" Password = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" FtpSecure = [WinSCP.FtpSecure]::Implicit } $session = New-Object WinSCP.Session try { # Connect $session.Open($sessionOptions) # Transfer files $session.PutFiles("C:\Folder\Folder\File.txt", "/site/wwwroot/pki/*").Check() } finally { $session.Dispose() } } until ($index -eq 10)