.net 怎么读取远程服务器文件夹目录 服务器!! 服务器 !!服务器!!

想根据服务器连接地址读取特定文件夹目录 不知道怎么写 求解答;不是本地 是服务器;;不是下载是读取文件夹下面所有的文件信息 !!!谢谢 111

看你服务器用的什么协议,什么服务器端。

假设是标准的http/ftp客户端。服务器上装了iis,开了80/21端口,有公网ip就可以做到。

那客户端C#用webclient.DownloadFile或者ftpWebRequest就可以下载。

#region 文件下载
public bool DownLoadFile(string localPath, string hostURL, int byteCount, string userID, long cruuent)
{

       bool result = true;


       string tmpURL = hostURL;

       byteCount = byteCount * 1024;
       hostURL = tmpURL + "&npos=" + cruuent.ToString();

       System.IO.FileStream fs;  
       fs = new FileStream(localPath, FileMode.OpenOrCreate);
       if (cruuent > 0)
       {
           //偏移指针
           fs.Seek(cruuent, System.IO.SeekOrigin.Current); 
       }


       System.Net.HttpWebRequest request = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(hostURL);
       if (cruuent > 0)
       {
           request.AddRange(Convert.ToInt32(cruuent));    //设置Range值
       }

       try
       {
           //向服务器请求,获得服务器回应数据流
           System.IO.Stream ns = request.GetResponse().GetResponseStream();

           byte[] nbytes = new byte[byteCount];
           int nReadSize = 0;
           nReadSize = ns.Read(nbytes, 0, byteCount);

           while (nReadSize > 0)
           {
               fs.Write(nbytes, 0, nReadSize);
               nReadSize = ns.Read(nbytes, 0, byteCount);

           }
           fs.Close();
           ns.Close();
       }
       catch(Exception ex)
       {
           LOG.Error("下载" + localPath + "的时候失败!" + "原因是:" + ex.Message);
           fs.Close();
           result = false;
       }
       return result;     
   }
   #endregion 

读取文件夹下的所有文件夹

我最近开发了一个FTP多线程下载程序,用到了你提到的获取目录功能;
具体方法如下:

 FtpWebRequest request=(FtpWebRequest)FtpWebRequest.Create(new Uri(ftpURI));//ftpURI为你指定的远程目录;
 request.Method = WebRequestMethods.Ftp.ListDirectory;//设置FTP命令获取指定文件夹下的文件列表
 //下边要定义变量
 response = reqFTP.GetResponse();
 reader = new StreamReader(response.GetResponseStream(), ftpencode);
 line = reader.ReadLine(); //这里为返回的目录细节

注意流的关闭操作

使用Directory.类可以实现对整个文件夹的操作,如删除,移动,改名等string path = Server.MapPath("/Files/"); //文件夹路径string[] paths = Directory.GetFiles(path); //获取文件夹下全部文件路径List files = new List(); foreach (string filepath in paths) { FileInfo file = new FileInfo(filepath); //获取单个文件 files.Add(file); }return files; //所有文件

FtpWebRequest request=(FtpWebRequest)FtpWebRequest.Create(new Uri(ftpURI));//ftpURI为你指定的远程目录;
request.Method = WebRequestMethods.Ftp.ListDirectory;//设置FTP命令获取指定文件夹下的文件列表
//下边要定义变量
response = reqFTP.GetResponse();
reader = new StreamReader(response.GetResponseStream(), ftpencode);
line = reader.ReadLine(); //这里为返回的目录细节

问题表述不清楚没法回答啊。服务器是ftp还是http至少要说清楚。

网上搜跨域访问。如同部署flash项目。把服务器的目录配置为网站。然后访问它。