Re: yes, it works in a normal winscp session
What do you mean by "normal winscp session"? WinSCP GUI? Or your code in a normal interactive Windows session?
Can you post a session log (not debug log) file from both your code and the working session?
Can you post a session log (not debug log) file from both your code and the working session?