Solved

Copy a file in SQL Server using xp_cmdshell

Posted on 2014-07-30
2
2,943 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

In this article I will describe the Detach & Attach 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.
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

706 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

18 Experts available now in Live!

Get 1:1 Help Now