Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Moving a file between 2 machines on a lan

Posted on 1998-11-17
5
Medium Priority
?
191 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 150 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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

715 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