Speed โ€‹โ€‹up dir_creation () on a restricted remote server

I have a problem creating directories in a shared folder on a remote machine with boost create_directories (). I only have access to this part. But I am creating a connection with user credentials with full read and write access.

The connection is allowed using WNetAddConnection2. The application should then create the directories "\ 139.22.XXX.XXX \ temp \ Test \ 1" and the connection will be disconnected using WNetCancelConnection2.

The code is shown below:

using namespace boost::filesystem;

typedef boost::filesystem::path Path;
typedef boost::filesystem::basic_filesystem_error<boost::filesystem::path> boost_filesystem_error;


DWORD loginDicomImporter()
{
    DWORD dwRetVal;
    NETRESOURCE nr;
    DWORD dwFlags;

    LPTSTR remoteName = _T("\\\\139.22.XXX.XXX\\temp");

    nr.dwType = RESOURCETYPE_ANY;
    nr.lpLocalName = NULL;
    nr.lpRemoteName = remoteName;
    nr.lpProvider = NULL;

    dwFlags = CONNECT_TEMPORARY;

    dwRetVal = WNetAddConnection2(&nr, _T("xxxPWDxxx"), _T("xxxUSERxxx"), dwFlags);

    if (dwRetVal == NO_ERROR)
    {

        return dwRetVal;
    }
    else
    {

        return dwRetVal;
    }

}

DWORD logoutDicomImporter()
{

    DWORD dwResult;
    LPCTSTR lpName = _T("\\\\139.22.XXX.XXX\\temp");
    dwResult = WNetCancelConnection2(lpName, CONNECT_UPDATE_PROFILE, FALSE);

    if (dwResult == NO_ERROR)
    {

        return dwResult;
    }
    else if (dwResult == ERROR_NOT_CONNECTED)
    {

        return dwResult;
    }
    else
    {

        return dwResult;
    }

}

int main()
{
    DWORD loginResult;
    std::string directoryPath = "\\\\139.22.XXX.XXX\\temp\\Test\\1";

    loginResult = loginDicomImporter();

    std::cout << loginResult << std::endl;

    try
    {
        boost::filesystem::create_directories(directoryPath);
    }
    catch (boost_filesystem_error &e)
    {
        auto msg = e.what();
        return 1;
    }


    loginResult = logoutDicomImporter();
    std::cout << loginResult << std::endl;
}

      

The thrown exception says "boost :: filesystem :: create_directory: Access denied:" \ 139.22.XXX.XXX \ temp \ Test \ 1 "Obviously the OS is denying access, although I enabled full access connection before creating directories.

Any suggestions how to solve this?

+3


source to share


1 answer


Thank you for your answer to quik47. But the problem was that in my actual code I was using the servername alias for the directoryPath string.

I used to have this: std::string directoryPath = "\\\\ServerName\\temp\\Test\\1";

After your advice, I replaced it with my ip address.



Now directory creation works as shown above.

0


source







All Articles