dbTalk Databases Forums  

how to copy files using xp_cmdshell

comp.databases.ms-sqlserver comp.databases.ms-sqlserver


Discuss how to copy files using xp_cmdshell in the comp.databases.ms-sqlserver forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
SJM
 
Posts: n/a

Default how to copy files using xp_cmdshell - 11-18-2007 , 03:57 AM






Howdy, hope someone can help me out with this.
I want to run a job each night that copies files from one server to another.
I cant even get a simple copy one file from one directory to another,
statement to work.
When I try :

@cmd 'copy c:\temp\file1.txt c:\backups\file1.txt'
master.dbo.xp_cmdshell @cmd

I get the msg: 'c' is not recognised as an internal command, program or
batch file, Null.

What I ideally want to do is pass xp_cmdshell variables for the 2 file's
path+names. I have tried numerous variations of single and double quotes
without success, which is why I decided to work up form the simple 'copy
c:\temp\file1.txt c:\backups\file1.txt', but can't even get that to work.
Any advice much appreciated.



Reply With Quote
  #2  
Old   
Erland Sommarskog
 
Posts: n/a

Default Re: how to copy files using xp_cmdshell - 11-18-2007 , 04:15 AM






SJM (na) writes:
Quote:
Howdy, hope someone can help me out with this. I want to run a job each
night that copies files from one server to another. I cant even get a
simple copy one file from one directory to another, statement to work.
When I try :

@cmd 'copy c:\temp\file1.txt c:\backups\file1.txt'
master.dbo.xp_cmdshell @cmd

I get the msg: 'c' is not recognised as an internal command, program or
batch file, Null.

What I ideally want to do is pass xp_cmdshell variables for the 2 file's
path+names. I have tried numerous variations of single and double quotes
without success, which is why I decided to work up form the simple 'copy
c:\temp\file1.txt c:\backups\file1.txt', but can't even get that to work.
Any advice much appreciated.
I would guess you have made a mistake in the declaration of @cmd:

DECLARE @cmd varchar

this is the same as

DECLARE @cmd varchar(1)



--
Erland Sommarskog, SQL Server MVP, esquel (AT) sommarskog (DOT) se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx


Reply With Quote
  #3  
Old   
Madhivanan
 
Posts: n/a

Default Re: how to copy files using xp_cmdshell - 11-21-2007 , 06:52 AM



On Nov 18, 3:15 pm, Erland Sommarskog <esq... (AT) sommarskog (DOT) se> wrote:
Quote:
SJM (na) writes:
Howdy, hope someone can help me out with this. I want to run a job each
night that copies files from one server to another. I cant even get a
simple copy one file from one directory to another, statement to work.
When I try :

@cmd 'copy c:\temp\file1.txt c:\backups\file1.txt'
master.dbo.xp_cmdshell @cmd

I get the msg: 'c' is not recognised as an internal command, program or
batch file, Null.

What I ideally want to do is pass xp_cmdshell variables for the 2 file's
path+names. I have tried numerous variations of single and double quotes
without success, which is why I decided to work up form the simple 'copy
c:\temp\file1.txt c:\backups\file1.txt', but can't even get that to work.
Any advice much appreciated.

I would guess you have made a mistake in the declaration of @cmd:

DECLARE @cmd varchar

this is the same as

DECLARE @cmd varchar(1)

--
Erland Sommarskog, SQL Server MVP, esq... (AT) sommarskog (DOT) se

Books Online for SQL Server 2005 athttp://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books...
Books Online for SQL Server 2000 athttp://www.microsoft.com/sql/prodinfo/previousversions/books.mspx- Hide quoted text -

- Show quoted text -
IMO, it should throw error saying "Length is not specified"
Sometimes it becomes tedius to debug if you forget to specify column
width


Reply With Quote
  #4  
Old   
Erland Sommarskog
 
Posts: n/a

Default Re: how to copy files using xp_cmdshell - 11-21-2007 , 04:11 PM



Madhivanan (madhivanan2001 (AT) gmail (DOT) com) writes:
Quote:
IMO, it should throw error saying "Length is not specified"
Sometimes it becomes tedius to debug if you forget to specify column
width
Yes, the default of 1 is silly.

While not explicitly mentioned, this is typically something that should
be flagged when SET STRICT_CHECKS ON is in effect, a SET option which I
have suggested in
https://connect.microsoft.com/SQLSer...dbackID=260762.

Votes are welcome!



--
Erland Sommarskog, SQL Server MVP, esquel (AT) sommarskog (DOT) se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.