Found the error. The user did not have modify permissions on the directory.
I am new to WinSCP and I am using the following argument in task scheduler
/log=E:\Winscp_logs\winscp.log /command "open sftp://username:pwd@Hostname/" "get -neweronly *.txt C:\newdirectory\" "mv *.* *.php"
For some reason, the file gets downloaded but did not get renamed. I have also tried using rm *.* that does not work either. Log shows Permission Denied.
Script: Error deleting file 'New Text Document (2).txt'.
Script: Permission denied.
Error code: 3
Error message from server (en): Permission denied.
I even changed the file permission but that did not resolve the issue.