情况如下:我现在在做一个项目时要实现一个文件传输功能,其中要给另外一台计算机传输文件目录,不过接受方(服务器)是被动的,所以我在发送文件之前要选择文件存放的路径,不过怎么获得对方计算机的文件目录结构我不知道该怎么办
我想是把服务器的文件目录信息使用树形结构显示出来,让用户选择
请大家指个方向和思路,该怎么做,或者怎么搜相关的资料,我不知道该怎么形容这个事情,呵呵,搜了半天没搜到什么东西
我想是把服务器的文件目录信息使用树形结构显示出来,让用户选择
请大家指个方向和思路,该怎么做,或者怎么搜相关的资料,我不知道该怎么形容这个事情,呵呵,搜了半天没搜到什么东西
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","[email protected]"); 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();
}
}
}
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","[email protected]");
// 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();
}
}
}
}
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","[email protected]"); 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();
}
}
}
可能我没说清楚,我要C/S模式的,并且我也没有架设FTP,我不可能再为了获取个目录再做个FTP吧
我再考虑下别的方式