Link to home
Start Free TrialLog in
Avatar of brad2575
brad2575Flag for United States of America

asked on

SQL xp_cmdshell copy files not working using network path

I am running into a problem when trying to copy a file using xp_cmdshell in SQL 2005 using a network path (works fine using a local path).  Assuming some sort of permissions issue but not sure why/how.

I have the script:
EXEC master.dbo.xp_cmdshell 'copy c:\test.txt c:\temp\'

This works fine but when I try to use the network paths (to the same exact folders just using the network paths it does not work with "Access denied" message.

EXEC master.dbo.xp_cmdshell 'copy \\ServerName\C$\test.txt \\ServerName\C$\temp\'


The folders are the exact same:
C:\ = \\ServerName\C$\
c:\temp = \\ServerName\C$\temp\


just not sure why it works using local paths but NOT server paths.



Avatar of ralmada
ralmada
Flag of Canada image

That's because the SQL account executing that procedure need access to that OS network path.
Avatar of brad2575

ASKER

It should already have it.  The account on the server is running SQL under a network ID that should have the permissions already.

The network path is the same as the local path (just going through the network).  What is the difference and how would I tell if it does not have it and how could I get it added then.
ASKER CERTIFIED SOLUTION
Avatar of ralmada
ralmada
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Another possibility is running this in SQL

exec xp_cmdshell 'whoami'
And then make sure that the service account has access to the folder in question.