SQL xp_cmdshell copy files not working using network path

Posted on 2009-04-16
Last Modified: 2013-12-04
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.

Question by:brad2575
    LVL 41

    Expert Comment

    That's because the SQL account executing that procedure need access to that OS network path.
    LVL 16

    Author Comment

    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.
    LVL 41

    Accepted Solution

    LVL 41

    Expert Comment

    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.

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    Join & Write a Comment

    Users of Windows 10 Professional can disable automatic reboots using the policy editor. This tool is not included in the Windows home edition. But don't worry! Follow the instructions below to install (a Win7) policy editor on your Windows 10 Home e…
    In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now