Solved

Moving a file between 2 machines on a lan

Posted on 1998-11-17
5
184 Views
Last Modified: 2012-05-04
Is there a class in mfc which facilites the moving of files between two machines on a lan by hostname?
0
Comment
Question by:kjsmith3
  • 3
  • 2
5 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 50 total points
ID: 1178064
Well, there's no class for it. But you simply could use the Win32 API 'CopyFile()' (or 'MoveFile()') that works with UNC names...
So a simple class could look like this:

class CLANCopyFile
{
  CLANCopyFile ( CString& strSrcPath, CString& strDstPath, CString& strDstHost)
  {
    CString strDstUNC;

    if ( *( strDstPath.GetBuffer( 0)) + 1) == ':') // check for drive letter
       { // strip it off, if present
         strDstPath = strDstPath.Right ( strDstPath.GetLength() -2);
       }
    if ( *( strDstPath.GetBuffer( 0)) + 1) != '\\') // check for '\'
       {
         strDstPath = CString( "\\") + strDstPath;
       }

    strDstUNC.Format( "\\\\%s%s", strDstHost, strDstPath);

    if ( !::CopyFile( ( LPCTSTR) strSrcPath, ( LPCTSTR) strDstUNC))
       {
         // error...
       }
  }

};


0
 
LVL 86

Expert Comment

by:jkr
ID: 1178065
Ooops ;-)

This was typed from scratch, so no guarantee for typos ;-)
0
 

Author Comment

by:kjsmith3
ID: 1178066
Could you please specify what the input would like if move data file h:\\winnt\myapp to newMachine:\winnt\myapp?

Thanx

0
 

Author Comment

by:kjsmith3
ID: 1178067
Could you please specify what the input would like if move data file h:\\winnt\myapp to newMachine:\winnt\myapp?

Thanx

0
 
LVL 86

Expert Comment

by:jkr
ID: 1178068
OK, the intention is the following:

Source file is e.g. e:\mydata\data.txt
Destination should be 'ourserver'
Destination file should reside id \share\path
(oops - now i see my own mistake - simply removing a possible drive letter is wrong, as the drive/share association can only be made on the server side)

Well, to make it simple - the API call should be like this:
if ( !::CopyFile( "e:\\mydata\\data.txt", "\\\\ourserver\\share\\path\\data.txt"))
{
 // error...
}
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Excel/Word Add-in in what language? 5 128
best sources to up-to-date in C++? 8 91
How to convert MFC::CString to UTF8 wchar_t* 10 279
I could not set window to top 4 20
Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

860 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