Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Import/Export (DTS) and Replication (2000)
 xp_cmdshell or ActiveX script

Author  Topic 

lee_h
Starting Member

36 Posts

Posted - 2003-03-20 : 22:35:28
I want to copy some text files from one server to another as part of an over night job.

If the source file doesn't exist or the destination file does exist then I don't want to copy the file.

I've done it two ways:

1. With an ActiveX script in a DTS package using the FileSystem object

2. With a Stored Procedure using xp_cmdshell


exec master..xp_cmdshell 'copy "\\server1\source\file.txt \\server2\dest\"'

overwrites the file if it exists in the destination.


I have more control over the File system using ActiveX, but have more control over where and when I use the procedure.

So, which one?
How do I check the existance of a file in the procedure?


Merkin
Funky Drop Bear Fearing SQL Dude!

4970 Posts

Posted - 2003-03-20 : 22:48:47
Well, by answering this I accidentally get my post count to go up one... yay, that is, after all, the only reason I am here.


Have you had a look at the robocopy.exe utility ? You should be able to find it either somewhere at Microsoft, on an NT resource kit CD or around on the net.

It works like "copy" but has lots of command line options to control what gets copied. It should be able to help.

Otherwise, script is probably the way to go.


Damian
Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2003-03-20 : 22:55:58
Well, far be it for me to post something just to get my post count up...ooooops, too late...

Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2003-03-20 : 22:56:47
Oh wait, that's right, I DID have a reply, but since we only post here to inflate our post count needlessly, it would've been dumb for me to actually post something useful...

Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2003-03-20 : 23:00:49
Ah yes, the answer: you CAN do this very easily with xp_cmdshell, and it's just as flexible as ActiveX. Here's an example:

xp_cmdshell 'if exist \\server1\source\file.txt if not exist \\server2\dest\file.txt copy \\server1\source\file.txt \\server2\dest\file.txt'

If is a batch command just like any other if statement. The command line will test for the existence of file1 on server1, if it's not there it will stop processing. If it IS there, then the next if tests for the non-existence of the destination file. If it does exist, it stops processing. Only if both conditions are true will the copy operation happen.

Wow! What a great way to get 3 more posts!

Go to Top of Page

Merkin
Funky Drop Bear Fearing SQL Dude!

4970 Posts

Posted - 2003-03-20 : 23:02:31
Wow, so THAT is how you do it without having to post crap in the yak corral. Thanks Rob!

Damian
Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2003-03-20 : 23:03:08
You're welcome!

Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2003-03-20 : 23:03:41
Oh yeah, I forgot to add that naturally you can dynamically build the command string to use any file name or location you want.

Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2003-03-20 : 23:04:29
Well, I didn't ACTUALLY forget, I didn't post it in the same reply because that would've defeated the whole purpose of posting stuff just to increase my post count! Which is why we're all here anyway!

Go to Top of Page

Merkin
Funky Drop Bear Fearing SQL Dude!

4970 Posts

Posted - 2003-03-20 : 23:04:54
Hey now, you could have just edited your orignal solution! That is just a waste of a post....DAMN

Damian
Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2003-03-20 : 23:05:32
Yeah, but if you look at MY post count, then YOUR post count...

Go to Top of Page

Merkin
Funky Drop Bear Fearing SQL Dude!

4970 Posts

Posted - 2003-03-20 : 23:07:02


That is really upsetting to me. If I can't use my wildly inflated post count as a measure of self worth, what CAN I use ?

Lee what do you think ?

Damian

Edited by - merkin on 03/20/2003 23:07:26
Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2003-03-20 : 23:08:24
Dude, why did you edit the original? Just post a correction instead!

Go to Top of Page

Merkin
Funky Drop Bear Fearing SQL Dude!

4970 Posts

Posted - 2003-03-20 : 23:09:19
I have much to learn

Damian
Go to Top of Page

lee_h
Starting Member

36 Posts

Posted - 2003-03-20 : 23:22:58
Merkin in Australia, so I can understand the 11pm posts.

Go to Top of Page

lee_h
Starting Member

36 Posts

Posted - 2003-03-20 : 23:23:23
But robvolk, do you have a life?

Go to Top of Page

lee_h
Starting Member

36 Posts

Posted - 2003-03-20 : 23:24:03
Woohoo 15 posts!!!
Can I merge the 34 from my other incarnation?


Go to Top of Page

Merkin
Funky Drop Bear Fearing SQL Dude!

4970 Posts

Posted - 2003-03-20 : 23:26:25
quote:

But robvolk, do you have a life?





Yeah, giving his spare time to help ungrateful people.. Can you imagine such a thing.


Damian
Go to Top of Page

lee_h
Starting Member

36 Posts

Posted - 2003-03-20 : 23:46:19
very greatful!

But I can see how you may feel unloved by us "Starting Members".

I'm the guy who posts thanks - but only so I can get my count up.

This is for the both of you

Go to Top of Page
   

- Advertisement -