如何向服务器读写文件

zhihaozwj 2008-06-05 08:24:14
如何把本地的文件存到服务器上,服务器是带密码的,密码我知道,如何通过代码实现???请指教,最好有代码
...全文
128 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
shuihan20e 2008-06-06
  • 打赏
  • 举报
回复
可以COPY过去,先登录了,然后copy(sourcefile,destfile:string);

或都使用idftp或者=====
大大怪老张 2008-06-06
  • 打赏
  • 举报
回复
楼主如果想利用文件共享功能传输文件的话,可以用僵哥说的方法,不过僵哥的 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 程序处理文件传输了。
hongqi162 2008-06-06
  • 打赏
  • 举报
回复
写个socket应用程序
雄牛 2008-06-06
  • 打赏
  • 举报
回复


~~~~~路过~~~~~~
~~~~友情UP~~~~~~~


僵哥 2008-06-05
  • 打赏
  • 举报
回复
WNetConnectionAdd2可以带密码建议IPC连接,然后如果服务器有共享目录的话,就可以使用
\\%servername%\%sharename%\%path%\%filename.ext%
进行直接访问

16,749

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 语言基础/算法/系统设计
社区管理员
  • 语言基础/算法/系统设计社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧