473,386 Members | 1,602 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

how to copy files using xp_cmdshell

SJM
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.
Nov 18 '07 #1
3 17695
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, es****@sommarskog.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
Nov 18 '07 #2
On Nov 18, 3:15 pm, Erland Sommarskog <esq...@sommarskog.sewrote:
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...@sommarskog.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
Nov 21 '07 #3
Madhivanan (ma************@gmail.com) writes:
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, es****@sommarskog.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
Nov 21 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Kay Lee | last post by:
Hi, I looked up os module to find out some method to move and copy files in python, but os doesn't support such methods. Is there any way to move & copy files in python? Thanks in adv.
3
by: Kay Lee | last post by:
Hi, I looked up os module to find out some method to move and copy files in python, but os doesn't support such methods. Is there any way to move & copy files in python? Thanks in adv.
3
by: Terri | last post by:
I'm using xp_cmdshell to output a text file from a trigger like this CREATE TRIGGER ON tblApplications FOR INSERT AS DECLARE @FirstName varchar(75) DECLARE @LastName varchar(75) Declare...
4
by: Joel Thornton | last post by:
Whenever something is inserted to a given table, I want to run some shell commands using xp_cmdshell. Would it be a bad idea to put this xp_cmdshell in the INSERT trigger of this table? I...
14
by: **--> That Guy Downstairs | last post by:
What files are needed to be #included to be able to copy files to a new directory and be portable? ie. use it in Unix (SGI and Linux) or Windows 2000. #ifdefs Ok. using dirent.h on SGI, but...
1
by: dkmarni | last post by:
Hi, I am trying to do this perl script, but not able to complete it successfully. Here is the description what the script has to do.. Accept two and only two command line arguments. Again,...
3
by: =?Utf-8?B?U2Vhbk1hYw==?= | last post by:
How do I programmatically copy files across a network (from a local workstation to another local workstation on the network) using visual basic 2005? In other words, when in explorer and you enter...
1
by: jazzy121 | last post by:
i want to copy a file usind default share on to the other pc which is also on lan and in same domain as well. the user from wich have logged on have full permissions. but when i try to copy the...
3
by: kavijaya | last post by:
filename to be copied,the source path and destination path are provided as input from .net app.When I copy file using xp_cmdshell copy /y sourcepath destinationpath the file is copied but the...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.