Yes it should work. Regarding the antivirus application: Try to turn off antivirus temporarily and see if it makes a difference.
- martin
Isn't there some server-side process that processes the uploaded files, which did not finish yet at the time of the next run?
It can even simply be an antivirus application.
Access is denied
$FTPHost = 'someserver'
$FTPUser = 'someuser'
$FTPPass = '*******'
$srcFolder = "D:\testUploadData"
$destPath = 'testFolder'
$destTmpPath = "${destPath}.TMP"
$destOldPath = "${destPath}.OLD"
try {
# Load WinSCP .NET assembly
Add-Type -Path (Join-Path $PSScriptRoot "..\winscp_assembly\WinSCPnet.dll")
$sessionOptions = New-Object WinSCP.SessionOptions -Property @{
Protocol = [WinSCP.Protocol]::Ftp
HostName = $FTPHost
UserName = $FTPUser
Password = $FTPPass
}
$session = New-Object WinSCP.Session
$session.SessionLogPath = 'log.txt'
try {
Write-Host("Connecting to FTP")
$session.Open($sessionOptions)
Write-Host("Creating .TMP dir")
if($session.FileExists($destTmpPath)) {
$session.RemoveFiles($destTmpPath).Check()
}
$session.CreateDirectory($destTmpPath)
Write-Host("Uploading to .TMP dir")
$session.PutFiles($srcFolder, $destTmpPath).Check()
Write-Host("Renaming live dir to .OLD")
if(!$session.FileExists($destPath)) {
$session.CreateDirectory($destPath)
}
if($session.FileExists($destOldPath)) {
$session.RemoveFiles($destOldPath).Check()
}
$session.MoveFile($destPath, $destOldPath)
Write-Host("Renaming .TMP dir to live")
$session.MoveFile($destTmpPath, $destPath)
Write-Host("Removing .OLD dir")
$session.RemoveFiles($destOldPath).Check()
}
finally {
$session.Dispose()
}
exit 0
}
catch {
Write-Host "Error: $($_.Exception.Message)"
exit 1
}