Solved

Moving a file between 2 machines on a lan

Posted on 1998-11-17
5
174 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
Comment Utility
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
Comment Utility
Ooops ;-)

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

Author Comment

by:kjsmith3
Comment Utility
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
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
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 be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

743 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