question

David 2 1 avatar image
David 2 1 asked

How To Configure xp_cmdshell To Access Remote Server?

Hi there, I'm trying to get xp_cmdshell to provide a directory listing of all files and folder on a remote server. When I run the command in a command prompt window it executes fine: dir \\files\1234 However whenever I try to execute the same command from query analyzer using xp_cmdshell it errors: "Logon failure: unknown user name or bad password." The command I am running is: exec master.dbo.xp_cmdshell 'dir \\files\1234' How to configure the xp_cmdshell to execute successfully on the remote server? TIA.
sqltsqlxp_cmdshell
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Kev Riley avatar image
Kev Riley answered
When you run 'dir \\files\1234' on the command line you are executing as you (or whatever account you are logged in as). When you do it through SQL Server using xp_cmdshell, it is using the credentials of the SQL Server service. So it's likely that those 2 accounts have different access rights over the UNC path.
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.