怎么获得局域网另外一台计算机的文件目录?

narcissus22 2010-01-31 05:39:16
情况如下:我现在在做一个项目时要实现一个文件传输功能,其中要给另外一台计算机传输文件目录,不过接受方(服务器)是被动的,所以我在发送文件之前要选择文件存放的路径,不过怎么获得对方计算机的文件目录结构我不知道该怎么办
我想是把服务器的文件目录信息使用树形结构显示出来,让用户选择
请大家指个方向和思路,该怎么做,或者怎么搜相关的资料,我不知道该怎么形容这个事情,呵呵,搜了半天没搜到什么东西
...全文
155 16 打赏 收藏 转发到动态 举报
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
slq19851208 2011-09-29
  • 打赏
  • 举报
回复
我也在寻找这样的解决办法
narcissus22 2010-02-08
  • 打赏
  • 举报
回复
我使用TcpClient与TcpListener基本实现功能了
danai0925 2010-02-01
  • 打赏
  • 举报
回复
每日回帖即可获得10分可用分,继续去睡觉
limii 2010-02-01
  • 打赏
  • 举报
回复
up
amaxman 2010-02-01
  • 打赏
  • 举报
回复
自己写一个WebService/windows Service返回指定目录的文件目录
narcissus22 2010-02-01
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 donggeng008 的回复:]
转自MSCN,供参考,下载文件
using System;
using System.IO;
using System.Net;
using System.Text;

namespace Examples.System.Net
{
   ...
[/Quote]
嗯,这个....
可能我没说清楚,我要C/S模式的,并且我也没有架设FTP,我不可能再为了获取个目录再做个FTP吧
我再考虑下别的方式
zyc_0204 2010-01-31
  • 打赏
  • 举报
回复
记得有个校园网聊天软件絮语 可以以"资源管理器"的形式,看到对方共享给你的文件,并双击可以下载.不知道怎么实现的.
donggeng008 2010-01-31
  • 打赏
  • 举报
回复
转自MSDN,供参考,获取服务器目录
using System;
using System.IO;
using System.Net;
using System.Text;

namespace Examples.System.Net
{
public class WebRequestGetExample
{
public static void Main ()
{
// Get the object used to communicate with the server.
FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp://www.contoso.com/");
request.Method = WebRequestMethods.Ftp.ListDirectoryDetails;

// This example assumes the FTP site uses anonymous logon.
request.Credentials = new NetworkCredential ("anonymous","janeDoe@contoso.com");

FtpWebResponse response = (FtpWebResponse)request.GetResponse();

Stream responseStream = response.GetResponseStream();
StreamReader reader = new StreamReader(responseStream);
Console.WriteLine(reader.ReadToEnd());

Console.WriteLine("Directory List Complete, status {0}", response.StatusDescription);

reader.Close();
response.Close();
}
}
}
donggeng008 2010-01-31
  • 打赏
  • 举报
回复
转自MSND,供参考,上载文件
using System;
using System.IO;
using System.Net;
using System.Text;

namespace Examples.System.Net
{
public class WebRequestGetExample
{
public static void Main ()
{
// Get the object used to communicate with the server.
FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp://www.contoso.com/test.htm");
request.Method = WebRequestMethods.Ftp.UploadFile;

// This example assumes the FTP site uses anonymous logon.
request.Credentials = new NetworkCredential ("anonymous","janeDoe@contoso.com");

// Copy the contents of the file to the request stream.
StreamReader sourceStream = new StreamReader("testfile.txt");
byte [] fileContents = Encoding.UTF8.GetBytes(sourceStream.ReadToEnd());
sourceStream.Close();
request.ContentLength = fileContents.Length;

Stream requestStream = request.GetRequestStream();
requestStream.Write(fileContents, 0, fileContents.Length);
requestStream.Close();

FtpWebResponse response = (FtpWebResponse)request.GetResponse();

Console.WriteLine("Upload File Complete, status {0}", response.StatusDescription);

response.Close();
}
}
}
}
donggeng008 2010-01-31
  • 打赏
  • 举报
回复
转自MSCN,供参考,下载文件
using System;
using System.IO;
using System.Net;
using System.Text;

namespace Examples.System.Net
{
public class WebRequestGetExample
{
public static void Main ()
{
// Get the object used to communicate with the server.
FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp://www.contoso.com/test.htm");
request.Method = WebRequestMethods.Ftp.DownloadFile;

// This example assumes the FTP site uses anonymous logon.
request.Credentials = new NetworkCredential ("anonymous","janeDoe@contoso.com");

FtpWebResponse response = (FtpWebResponse)request.GetResponse();

Stream responseStream = response.GetResponseStream();
StreamReader reader = new StreamReader(responseStream);
Console.WriteLine(reader.ReadToEnd());

Console.WriteLine("Download Complete, status {0}", response.StatusDescription);

reader.Close();
response.Close();
}
}
}
丁码农 2010-01-31
  • 打赏
  • 举报
回复
这个需要映射磁盘。可以通过 Telent或者IPC$,登录对方的操作系统。
narcissus22 2010-01-31
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 wuyq11 的回复:]
局域网其他计算机的磁盘映射到本地磁盘驱动器
[/Quote]
不很明白,能不能说的再明白一点,谢谢
narcissus22 2010-01-31
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 wxm3630478 的回复:]
Socket

如果要客户端选择目录,那么就把选择的目录先传给服务器.服务器判断,有没有该目录,没有就创建

是否创建成功----发生一个结果给client,然后在发送文件

[/Quote]

我没办法把选择的目录传给服务器啊,我现在解决的就是客户机不知道服务器的目录,所以才想要服务器的目录的,现在获取不了服务器的目录,也就没办法选择之后再提供给服务器啊。
narcissus22 2010-01-31
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 wxm3630478 的回复:]
-------------------------

得到文件目录,不知道有什么直接方法没有.........

但是 可以用FileInfo  和 DirectoryInfo 把文件夹和文件 循环遍历出来.....发送给客户单
[/Quote]
嗯,遍历本地文件夹得话貌似问题还不大,我今天试了一下,关键是怎么遍历对方机器上的文件夹呢,更关键的是我遍历之后是个FileInfo对象和DirectoryInfo的对象,或者是个数组,我怎么传给客户机呢,我总不能写到文件里传过来再读吧,感觉太绕路了

wuyq11 2010-01-31
  • 打赏
  • 举报
回复
局域网其他计算机的磁盘映射到本地磁盘驱动器
wxm3630478 2010-01-31
  • 打赏
  • 举报
回复
Socket

如果要客户端选择目录,那么就把选择的目录先传给服务器.服务器判断,有没有该目录,没有就创建

是否创建成功----发生一个结果给client,然后在发送文件

-------------------------

得到文件目录,不知道有什么直接方法没有.........

但是 可以用FileInfo 和 DirectoryInfo 把文件夹和文件 循环遍历出来.....发送给客户单

111,120

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

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