Solved

How to remotely instruct a Server to do a file copy operation (and hopefully track progress)

Posted on 2014-09-24
6
155 Views
Last Modified: 2014-10-08
Hi,

We currently have a desktop application that I will be rewriting shortly.  One of its functions is to make a backup of a large file.  At the moment it simply does something like;  
file.copy(\\MyServer\MyFiles\myfile.txt, \\MyServer\MyBackups\[today.toString]\myfile.txt)

Open in new window

.  

But I reckon there must be a better way of doing this.  I was thinking that there could be a service of some sort running on the server, that receives a notification to run a copy operation.

I started looking at WCF but have no experience, and I couldn't find much help in providing progress.  There are plenty of examples of progress when uploading from client to server.  But I couldn't find anything about providing progress to the client when the operation is completely on the server-side.

any thoughts/suggestions?

Thanks
0
Comment
Question by:ITPOL
  • 3
  • 3
6 Comments
 
LVL 28

Expert Comment

by:Bill Bach
ID: 40344059
I am not aware of a pre-built service to schedule copy operations remotely -- as I believe that this would be a HUGE security hole waiting to be exploited if it were really a general-purpose tool.  I would therefore provide two possible suggestions:

1) If your backup can be run at a specific time via a Scheduled Task, then I would recommend going that route.  Every night, my server handles a bunch of file-copy operations to backup NAS devices and workstations, but these scripts all fire at the same time every night.
2) If you need to be able to flag the start time of the backup, then you'll need to write a simple program (VBScript or batch files would be easiest).  The easiest solution is to monitor a specific directory, looking for a specific file, such as GO.TXT.  If the file is not there, sleep for 30 seconds and check again.  When the file appears, read it to acquire the filename to copy and continue with the copy operation.  (You could make this even simpler by using GO.BAT and then simply call the batch file.)  After the file copy is done, delete the file.  If you need confirmation, you can create a DONE.TXT file in the same folder, and the client can monitor the folder for when it finishes (and delete the DONE.TXT file as an acknowledgement).
3) Of course, if you truly want a generic remote file copy service, it would be possible to write one.  You would build a service in Windows that posts a TCP Listener, waits for an inbound connection, and then receives the filename and target path, then performs the copy operation.  Adding in a check to the file size, and then copying block by block (instead of relying on the OS COPY commands) could allow for progress reports (i.e. percentage complete) to be sent to the client if needed.  Then, build a custom client GUI that accepts the file/target names, issues the TCP call to the server, and reports back on progress.  This probably could be done in 2-4 hours of development effort.  However, such a solution seems silly to write when pre-built solutions already exist, and I could EASILY see where this could be used to completely replace OS files if used incorrectly, making it a great hacking tool.  Let's just say that I wouldn't put it on MY server.
0
 
LVL 1

Author Comment

by:ITPOL
ID: 40344150
Thanks for the response, and your ideas.  Unfortunately options 1 and 2 aren't quite right in my particular scenario.

To elaborate a bit; the Fileserver holds around 500 database files.  The DBs are accessed across the network from the client desktops, not all DBs are in use at once, but any number up to about 15 could be.

The current business process (for which I am rewriting the app) has a certain trigger at which point it copies the DB file to a new date-named folder in a different directory on the server.  This is effectively a snaphot of the database, which can be used to restore to that point in time.

As it is the client that is carrying out the copy, I think it would be more efficient for the client to the notify the server to make the relevant backup.  Security concerns can easily be accounted for, the filepaths can be baked in to the logic of the server-side code, and the only parameter passed from client to the server could be the unique reference of the DB, and we're just talking file services here, not web-availability.

Having done some more reading I think that it may be WCF callbacks that I need to understand (unless there are other options?)
0
 
LVL 28

Expert Comment

by:Bill Bach
ID: 40344235
Option 2 would still be far easier (about 5 minutes of VBScript coding), and you would make it easy to extend the environment by just editing the script file text.  Is having a "copy progress" displayed really that critical?
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 1

Author Comment

by:ITPOL
ID: 40345811
Agreed it would be easier, but not quite as nice from an end user perspective.  It also means having some thing constantly polling the directories which isn't great.
0
 
LVL 28

Accepted Solution

by:
Bill Bach earned 500 total points
ID: 40346241
OK.  As long as you have a good set of reasons -- writing a service isn't impossible, but it just seems to be more work than I'd want to normally do for a file-copy process.  I did some searching this morning with various keywords, but could not come up with any pre-built solution today.  (I did manage to find a server-side copy, but without status details: http://msdn.microsoft.com/en-us/library/cc246361.aspx)   It doesn't mean that it doesn't exist -- just that I couldn't find one.  This just means that you'll have to write it yourself.

The way to go about it is to write a service that posts a TCP listener thread.  When the service receives a new connection, it gets an instruction to issue a file copy command, which can kick off the process based on your built-in file copy locations.  The file copy can easily be implemented with block I/O operations (say, 64KB at a time).  On a periodic basis, the process can send back status updates (i.e. percentage complete) to the client-side application, which would be able to display a progress bar on-screen.  When the copy is complete, the thread is shut down and the connection is terminated.  You'll then need to write the client-side code, too, to connect to the service, issue the command, receive status updates, etc.  Add in some firewall management to allow communications on the ports, and you have a solution.

The difficulty of the service shouldn't be too bad.  I'm sure you can find existing open-source services that already handle the TCP communications process (for both server and client), and the file copy is one simple WHILE loop, with something to send the status reports out.  As a programmer, you can likely figure this out from here.  I've not done a TCP listener in quite some time, but I've done some UDP work recently.  I'd be happy to help with additional suggestions, but need to know where you need additional advice.
0
 
LVL 1

Author Comment

by:ITPOL
ID: 40367871
Nice one thank you.  I'll take a look and see what I can come up with.
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

705 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now