如何复制文件到局域网中另一台机器(急,在线等!)
知道该机器的ip和用户名,密码,还有共享的文件名
如何复制文件过去啊?
比如目标机器 ip:192.168.1.99 用户名:admin 密码:123。在cb中如何点一个按钮来完成这个功能?
谢谢
[解决办法]
//相当于DOS命令 net use \\ip\share$ PassWord /user:UserNamebool NetConnect(char *netPath,char *user,char *pwd){ NETRESOURCE NetRes; memset(&NetRes, 0, sizeof(NETRESOURCE)); NetRes.dwScope=RESOURCE_CONNECTED; NetRes.dwType=RESOURCETYPE_ANY; NetRes.dwDisplayType=RESOURCEDISPLAYTYPE_GENERIC; NetRes.dwUsage=RESOURCEUSAGE_CONNECTABLE; NetRes.lpRemoteName=netPath; DWORD result=WNetAddConnection2(&NetRes,pwd,user,0); return(result==0); // 0: 正常}//相当于DOS命令 net use \\ip\share$ /deletebool NetCancel(char *netPath){ DWORD result=WNetCancelConnection2(netPath,0,true); return(result==0); // 0: 正常}char *sharePath="\\\\192.168.199.122\\ShareDir$";char *username1="shareread"; // 只读用户名char *username2="sharewrite"; // 可读可写用户名char *passwd="psw123";void __fastcall TForm1::OnlyReadClick(TObject *Sender){ // 只读 bool r=NetConnect(sharePath,username1,passwd); ShowMessage(r?"ok":"fail"); ShellExecute(0,"open",sharePath,0,0,SW_SHOW);}void __fastcall TForm1::WriteConnectClick(TObject *Sender){ // 可读可写 bool r=NetConnect(sharePath,username2,passwd); ShowMessage(r?"ok":"fail"); ShellExecute(0,"open",sharePath,0,0,SW_SHOW);}//---------------------------------------void __fastcall TForm1::UnconnectClick(TObject *Sender){ bool r=NetCancel(sharePath); ShowMessage(r?"ok":"fail");}
[解决办法]
NETRESOURCE nr;
TCHARszUserName[32] = "user", //遠端用戶名
szPassword[32] = "password", //密碼
szLocalName[32] = "Q:", //映射路徑
szRemoteName[MAX_PATH] = "\\\\192.168.XXX.XXX\\Share"; //遠端路徑
//使用以下方式映射遠端到指定的盤符.
DWORD res;
nr.dwType = RESOURCETYPE_ANY;
nr.lpLocalName = szLocalName;
nr.lpRemoteName = szRemoteName;
nr.lpProvider = NULL;
res = WNetAddConnection2(&nr, szPassword, szUserName, FALSE);
if(res == NO_ERROR)
;
else
ShowMessage("連接到網絡失敗.");
//解除映射
WNetCancelConnection2(szLocalName, 0, True);