Solved

Moving a file between 2 machines on a lan

Posted on 1998-11-17
5
190 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 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

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…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
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.
Suggested Courses

623 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