gpt4 book ai didi

c++ - boost create_directories() 在受限的远程服务器上失败

转载 作者:太空狗 更新时间:2023-10-29 23:14:50 28 4
gpt4 key购买 nike

我在使用 boost create_directories() 在远程计算机上的共享文件夹上创建目录时遇到问题。我只有阅读此共享的权限。但是我使用具有完全读写访问权限的用户凭据创建连接。

使用 WNetAddConnection2 启用连接。然后,应用程序应创建目录“\139.22.XXX.XXX\temp\Test\1”,并使用 WNetCancelConnection2 禁用连接。

代码如下:

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;
}

捕捉到的异常是“boost::filesystem::create_directory: Access denied: "\139.22.XXX.XXX\temp\Test\1"显然,操作系统拒绝访问。虽然我在创建目录之前启用了完全访问连接。

有什么解决办法的建议吗?

最佳答案

感谢 melak47 的快速回复。但问题是,在我的实际代码中,我使用了 directoryPath 字符串的服务器名别名。

以前,我是这样的:std::string directoryPath = "\\\\ServerName\\temp\\Test\\1"; 在听从你的建议后,我用它的 ip 地址替换了它。

现在创建目录的工作方式如上所示。

关于c++ - boost create_directories() 在受限的远程服务器上失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31855487/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com