Solved

Moving a file between 2 machines on a lan

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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

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 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.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

832 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