Access to a shared folder on other computer

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.

//***http://www.ibm.com/developerworks/aix/library/au-boostfs/
#include <stdio.h>
#include <boost/filesystem.hpp>
int main()
{
boost::filesystem::path path("/usr/local/include");
bool result = boost::filesystem::is_directory(path);
return 0;
}
It depends on the protocol you want to use. There is a variety of protocols for moving files from one computer to another.
In my limited knowledge in the Windows side, you can map a shared folder including username and password calling the function WNetAddConnection2(). You could also call CredUIPromptForCredentials() to quickly gather a username and password and use them in a call to LogonUser() that will grant you an impersonation token. Use the token to impersonate this new user and directly access the file share.

Just so it is 100% clear: I know NOTHING about Linux. :-( I cannot help out in making this portable.
Kbw and WebJose, tanks for your answers.
Kbw, can you give me an example in C++ of any protocol to move files in a windows7 and other protocol to move files in Linux? I know how to do locally but I have no idea how to do on other computer and if it's necessary, how to use a password if there is one. My program will ruin over linux but will access folders in both windows and linux.
Protocol choice is yours, but whatever protocol you use, you will need to run a server for it on the remote machine. Personally I would go with ssh as the protocol and libssh2 as the access library, but ftp, samba(ie CIFS), and webdav are 3 other perfectly good protocols off the top of my head.
Kev82, thanks for your answer. I am very C++ beginner. When you answered me with your personal opinion you helped me so much. Yesterday, I spent the whole day looking for a article or even better, an example how to do but I did not find it. Can you send me an example or indicate an tutorial about how to access a remote folder which need some parameters like password? I have been worked for only 4 weeks with C++ and I have been able to develop because I have been used libraries like Boost and LibCurl, which are very well explained and they make the work easier and faster. Probably it will exist some library to support what I am trying to do.

Kev82, I am sorry. I didn't note that you had already suggest me a library (libssh2). After short research about libssh2, I found some directions (http://www.libssh2.org/examples/). I will try it today. Anyway, thanks again.
If you want to use a name like \\192.168.x.x\mySharedFolder, then it means you're most probably using Windows and you're accessing 192.168.x.x over CFS, a Microsoft Network protocol that used to be called SMB. It's the default method for connecting Windows computers. Unix (including Apple OS X) computers can talk using this protocol using Samba, a package that implements SMB.

\\192.168.x.x\mySharedFolder uses a naming convention is called a UNC.

Because these protocols are usable implicitly from the files system, you don't need to do anything special in your program. You ought to be able to access a file \\192.168.x.x\mySharedFolder\README.TXT with:
1
2
3
4
5
6
7
8
9
10
11
12
13
#include <fstream>
#include <iostream>
#include <string>

int main()
{
    std::ifstream is("\\\\192.168.x.x\\mySharedFolder\\README.TXT");
    std::string line;
    while (std::getline(is, line))
        std::cout << line << std::endl;

    return 0;
}


You need double slashes because the slash character is a delimiter.
Last edited on
Topic archived. No new replies allowed.