Solved

Copying file from one server to another

Posted on 2014-02-22
7
234 Views
Last Modified: 2014-03-10
Hi,

 I have the names of file path in a MS SQL 2005 table in the following format:

Path Filename
Myfileserver\ABC  abc.txt
Myfileserver\DBC  dbc1.txt

etc

These can be dumped into a flat file called processfiles.txt residing on the SQL server, which would contain the following contents:
Myfileserver\ABC\abc.txt
Myfileserver\DBC\dbc1.txt

I wanted to write a batch script that will reside on a different server than the SQL server and will need to copy those files in the table and put them on a folder on the current server.

How do I accomplish this?
0
Comment
Question by:LuckyLucks
  • 3
  • 2
  • 2
7 Comments
 
LVL 14

Expert Comment

by:Don Thomson
ID: 39879668
something like this may work

for %%f in (Myfileserver\abc\*.txt) DO type %%f>>\\Otherfileserver\whateverfolder\processfiles.txt
do this for each folder
0
 
LVL 54

Accepted Solution

by:
Julian Hansen earned 500 total points
ID: 39879710
Is there any reason you can't dump the content from the SQL server directly to a BAT file. In other words

copy Myfileserver\ABC\abc.txt \\otherserver\path\abc.txt
copy ...

Open in new window

0
 

Author Comment

by:LuckyLucks
ID: 39879809
The problem is Myfileserver\ABC and Myfileserver\DBC etc are dynamically produced in the table. So prior to this question, there is a button thats presses, stuff happens and the table containing the two folder locations is created. It could  be a different number and name of folders the next time around. Each folder also may have a different number of files in it each time. Hence, any hardcoding is not going to work.
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 54

Assisted Solution

by:Julian Hansen
Julian Hansen earned 500 total points
ID: 39880635
No, what I mean is, as I understand your setup some process is producing a file
These can be dumped into a flat file called processfiles.txt residing on the SQL server, which would contain the following contents:

If this process is producing a list of files that another process (bat file) must read then why not simply create the output of the first file as bat commands.

If the destination is dynamic then use parameters i.e.
Output to movefiles.bat
copy Myfileserver\ABC\abc.txt %1
...

Open in new window

And call from second bat file

\\sqlserver\pathtobatfile\movefiles.bat \\someotherserver\somefolder

Open in new window

0
 
LVL 14

Expert Comment

by:Don Thomson
ID: 39881032
Do the original files have to be deleted?
0
 

Author Comment

by:LuckyLucks
ID: 39887378
no originals have to be deleted
0
 
LVL 54

Expert Comment

by:Julian Hansen
ID: 39888031
@LuckyLucas - any response to my previous post?
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Having trouble getting your hands on Dynamics 365 Field Service or Project Service trial? Worry No More!!!
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…

772 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