楼主如果想利用文件共享功能传输文件的话,可以用僵哥说的方法,不过僵哥的 api 写错了,正确的是 WNetAddConnection,WNetAddConnection2, WNetAddConnection3。 使用完后释放可以用 WNetCancelConnection 或者 WNetCancelConnection2。这是 msdn 中的例子:Assigning a Drive to a Share The following example demonstrates how to connect a drive letter to a remote server share with a call to the WNetAddConnection2 function. The sample informs the user whether or not the call was successful.Windows Me/98/95: This code sample is not supported. To test the following code sample, perform the following steps:Change the following lines to valid strings: szUserName[32] = "myUserName", szPassword[32] = "myPassword", szLocalName[32] = "Q:", szRemoteName[MAX_PATH] = "\\\\products2\\relsys";Add the file to a console application called AddConn2. Link the library MPR.LIB to the compiler list of libraries. Compile and run the program AddConn2.EXE. #include <windows.h> #include <stdio.h> #include <winnetwk.h>void main() { NETRESOURCE nr; DWORD res; TCHAR szUserName[32] = "MyUserName", szPassword[32] = "MyPassword", szLocalName[32] = "Q:", szRemoteName[MAX_PATH] = "\\\\products2\\relsys"; // // Assign values to the NETRESOURCE structure. // nr.dwType = RESOURCETYPE_ANY; nr.lpLocalName = szLocalName; nr.lpRemoteName = szRemoteName; nr.lpProvider = NULL; // // Call the WNetAddConnection2 function to assign // a drive letter to the share. // res = WNetAddConnection2(&nr, szPassword, szUserName, FALSE); // // If the call succeeds, inform the user; otherwise, // print the error. // if(res == NO_ERROR) printf("Connection added \n", szRemoteName); else printf("Error: %ld\n", res); return; } 如果不利用 文件共享 功能的话,就得自己写 socket 程序处理文件传输了。
\\%servername%\%sharename%\%path%\%filename.ext%
进行直接访问
The following example demonstrates how to connect a drive letter to a remote server share with a call to the WNetAddConnection2 function. The sample informs the user whether or not the call was successful.Windows Me/98/95: This code sample is not supported.
To test the following code sample, perform the following steps:Change the following lines to valid strings: szUserName[32] = "myUserName",
szPassword[32] = "myPassword",
szLocalName[32] = "Q:",
szRemoteName[MAX_PATH] = "\\\\products2\\relsys";Add the file to a console application called AddConn2.
Link the library MPR.LIB to the compiler list of libraries.
Compile and run the program AddConn2.EXE. #include <windows.h>
#include <stdio.h>
#include <winnetwk.h>void main()
{
NETRESOURCE nr;
DWORD res;
TCHAR szUserName[32] = "MyUserName",
szPassword[32] = "MyPassword",
szLocalName[32] = "Q:",
szRemoteName[MAX_PATH] = "\\\\products2\\relsys";
//
// Assign values to the NETRESOURCE structure.
//
nr.dwType = RESOURCETYPE_ANY;
nr.lpLocalName = szLocalName;
nr.lpRemoteName = szRemoteName;
nr.lpProvider = NULL;
//
// Call the WNetAddConnection2 function to assign
// a drive letter to the share.
//
res = WNetAddConnection2(&nr, szPassword, szUserName, FALSE);
//
// If the call succeeds, inform the user; otherwise,
// print the error.
//
if(res == NO_ERROR)
printf("Connection added \n", szRemoteName);
else
printf("Error: %ld\n", res);
return;
}
如果不利用 文件共享 功能的话,就得自己写 socket 程序处理文件传输了。