Before posting, please read how to report bug or request support effectively.

Bug reports without an attached log file are usually useless.

Options

If you do not want to add an Attachment to your Post, please leave the Fields blank.

(maximum 10 MB; please compress large files; only common media, archive, text and programming file formats are allowed)

Options

# Topic review

martin

## Re: Local files not being deleted during synchronization (PowerShell)

If your goal is to move all local files to a remote directory, you can do it with a single line of code:

Secondly, I was using $session.RemoveFiles($filename) to remove the local file, which would not work because it was prepending my file name with the root directory of the remote FTP server. Instead I used a straight up rm command to remove the local file, and the $? variable to determine success or failure of that operation. Anyway, I didn't find anything to point this out to me, so I thought I'd share in case others run across this. FF-SFTPHelp ## Local files not being deleted during synchronization (PowerShell) Hey Folks, I am in need of assistance in determining why local files aren't being deleted during a 'remote' transfer. The files present in the local directory are being transferred without issue, it's just the deletion that's being skipped. I used a template as the basis for the PowerShell script, but here is the section in question: $session.SessionLogPath = "C:\path\to\TransferLogPS.log"# Connect$session.Open($sessionOptions) # Synchronize files to Customer FTP server, collect results$synchronizationResult =$session.SynchronizeDirectories(    [WinSCP.SynchronizationMode]::Remote, $localDir,$remoteDir, $False) # Deliberately not calling$synchronizationResult.Check# as that would abort our script on any error.# We will find any error in the loop below# (note that $synchronizationResult.Downloads is the only operation# collection of SynchronizationResult that can contain any items,# as we are not removing nor uploading anything) # Iterate over every downloadforeach ($download in $synchronizationResult.Downloads){ # Success or error? if ($download.Error -eq $Null) { Write-Host "Download of$($download.FileName) succeeded, removing from source" # Download succeeded, remove file from source$filename = [WinSCP.RemotePath]::EscapeFileMask($download.FileName)$removalResult = $session.RemoveFiles($filename)         if ($removalResult.IsSuccess) { Write-Host "Removing of file$($download.FileName) succeeded" } else { Write-Host "Removing of file$($download.FileName) failed" } } else { Write-Host ( "Download of$($download.FileName) failed:$(\$download.Error.Message)")    }}

I have a nearly duplicate section (different variables) that copies from the remote FTP server to a local directory and successfully removes the files from the remote FTP server.

This template was originally for copying from remote and deleting remote files afterward, so I'm thinking I'm missing something I should have changed for it to work in the opposite direction.

Any help is much appreciated!