Solved

Copy a file in SQL Server using xp_cmdshell

Posted on 2014-07-30
2
3,012 Views
Last Modified: 2014-07-30
Hello Folks,

I wanted to copy a file with name "mts&Cs, MTC,MLA_77.rar" using xp_cmdshell in SQL Server 2012.

EXEC master..xp_cmdshell 'COPY D:\Source\mts&Cs, MTC,MLA_77.rar E:\Destination'

But, it is giving below error:
The system cannot find the file specified.
'Cs' is not recognized as an internal or external command,
operable program or batch file.
NULL

It seems that it does not allow "&", "," and space.

Could you please take a look over it and let me know in case you have other thoughts?

Best Regards,
Mohit Pandit
0
Comment
Question by:MohitPandit
2 Comments
 
LVL 39

Accepted Solution

by:
lcohan earned 500 total points
ID: 40229104
try to wrap it in quotes as below:

EXEC master..xp_cmdshell 'COPY "D:\Source\mts&Cs, MTC,MLA_77.rar" E:\Destination'


It will be something like below done in a CMD window right?


C:\>copy New Text Document.txt c:\lc
The system cannot find the file specified.

C:\>copy "New Text Document.txt" c:\lc
        1 file(s) copied.
0
 
LVL 5

Author Closing Comment

by:MohitPandit
ID: 40229158
Thank you for quick and accurate response.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

895 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

15 Experts available now in Live!

Get 1:1 Help Now