Solved

Copy a file in SQL Server using xp_cmdshell

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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
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.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

717 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