To be more specific, if I execute the following from a command window (i.e., a "DOS" window):
"C:\Progra~2\WinSCP\WinSCP.com" /command "open sftp://login:email@example.com:22" exit'
it works. But if I execute the following from SQL Server, I get the error "The directory name is invalid."
EXEC xp_cmdshell '"C:\Progra~2\WinSCP\WinSCP.com" /command "open sftp://login:firstname.lastname@example.org:22" exit'
xp_cmdshell is a SQL Server command that executes an external process. The problem isn't related to xp_cmdshell per se though, because if I execute the following, I don't get an error:
EXEC xp_cmdshell '"C:\Progra~2\WinSCP\WinSCP.com" /command session exit'
Instead, I get the message "No session", as I would expect.
So I'm pretty sure the message "The directory name is invalid" is coming from WinSCP, not SQL Server, and that it is in some way related to WinSCP's Open command. Somehow, WinSCP's Open command is behaving differently when called from SQL Server rather than by me. I should mention that when xp_cmdshell executes a command, it executes it under a different account (not mine). So this may be a permissions problem. However, the account SQL Server uses is an administrator on this machine.
Can anyone help?