Post a reply

Options
Add an Attachment

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

johnmcp

Of course! Should have spotted that :(

Thanks a lot Martin.
martin

So that's good.
I can see the real problem now:
You do not pass a path to the source file. You pass $fileInfo object (what converts to a mere filename, by an implicit call to .ToString).
Use $fileInfo.FullName.
johnmcp

The documentation also says this:
The name must be included or the target page has to end with a slash


I have set the value of $toPath to this:
$toPath = "/DataWarehouse/Dev/"

Noting that the trailing slash is included.

The exact error description is:
"Error moving file 'AMPS_Transactions.xlsx' to '/DataWarehouse/Dev/AMPS_Tr

ansactions.xlsx'.


Which would indicate to me that the $toPath variable is correct.[/quote]
martin

Re: Permission denied using MoveFile method

The second argument of Session.MoveFile is:

Full path to new location and name to move/rename the file to.

https://winscp.net/eng/docs/library_session_movefile

What $toPath hardly is, as you use the same same value for all files.
johnmcp

Permission denied using MoveFile method

I have created a simple Powershell script to move files from one location to another on the same server.
This is my code:
$session.Open($sessionOptions)


        #$files = $session.ListDirectory($remotePath)

        # Iterate over every transfer
        $fileInfos =
            $session.EnumerateRemoteFiles(
                $fromPath,
                $Null,
                [WinSCP.EnumerationOptions]::EnumerateDirectories -bor
                    [WinSCP.EnumerationOptions]::AllDirectories)

        foreach ($fileInfo in $fileInfos)
        {           
 
            if ($fileInfo.IsDirectory)
            {
                #TODO
               
            }
            else
            {
                $session.MoveFile($fileInfo, $toPath)
            }
        }


On executing the code I get a Permission denied error.
I have verified the user has the required permissions by performing the same move operation from the WinSCP GUI, so I don't know why I am getting this error when using the script.
Grateful if someone can provide advice on this.