Solved

Copy a file in SQL Server using xp_cmdshell

Posted on 2014-07-30
2
3,185 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 40

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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
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.

820 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