I found the problem. Removing the quotes from around the path to WinSCP solved it. In other words, if I change this:
to this:
I no longer get the "Directory is not valid" error. It's very weird that this error only occurs when I use xp_cmdshell and also use the Open command.
EXEC xp_cmdshell '"C:\Progra~2\WinSCP\WinSCP.com" /command "open sftp://login:password@sftp.someserver.com:22" exit'
to this:
EXEC xp_cmdshell 'C:\Progra~2\WinSCP\WinSCP.com /command "open sftp://login:password@sftp.someserver.com:22" exit'
I no longer get the "Directory is not valid" error. It's very weird that this error only occurs when I use xp_cmdshell and also use the Open command.