?
Solved

Copy a file in SQL Server using xp_cmdshell

Posted on 2014-07-30
2
Medium Priority
?
3,508 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 40

Accepted Solution

by:
lcohan earned 2000 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

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

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 article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Suggested Courses

743 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