Click here to Skip to main content
16,013,465 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Can someone send me a example of how to copy a file from a remote folder to other remote folder? For example: I am running MyProgram on MyComputer and this program has to copy a file from a folder inside OtherComputer. This folder need user and password to allow MyProgram to copy the file.
I am using the following sample. The main point in this example is to make my program to work both in linux and windows, but locally. Now I want to do the same with a path like this: \\192.168.x.x\mySharedFolder\fileToBeCopied.text . Maybe I need another library but I don't know. I imagine that there will be a way to set user, password and even proxy to get a file from other computer inside a shared folder.


C++
//***http://www.ibm.com/developerworks/aix/library/au-boostfs/
#include <stdio.h>
#include 
int main()
{
boost::filesystem::path path("/usr/local/include"); 
bool result = boost::filesystem::is_directory(path);
return 0;
}</stdio.h>
Posted
Updated 15-Sep-11 8:38am
v2

You might want to look into this API method:

C++
DWORD WNetAddConnection3(HWND hwndOwner,              // owner window
                         LPNETRESOURCE lpNetResource, // connection details
                         LPTSTR lpPassword,           // password string
                         LPTSTR lpUserName,           // user name string
                         DWORD dwFlags                // connection options);
 
Share this answer
 
Comments
Member 8202575 15-Sep-11 15:48pm    
John Simmons, tanks for your answer. Do you know some library to work in both linux and windows? My program will run over both linux and windows.
The relation between file and folders (either local or remote) is something pertinent to the operating system, not to applications.

If your account has the privilege to access a resource AND the network is properly configured, you can access whatever file with paths like "\\networkname\resourcename\folder\file".

In windows this is native by means of a protocol named CIFS, in Linux this is native by means to a protocol called NFS.
Both Windows and Linux have drivers to implement the other protocol over themselves.

If this doesn't work, check how the network is configured and how user account are authorized on the other machine.
Avoid to implement yourself "file communications" across the network. We already have all the standard needed and even more!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900