ftp.Connect(ftpIp,ftpUserName,ftpUserPassword);
 ftp.SetCurrentDirectory("/"+projectId +"/");            
 if(ftp.FileExist(filename)&&filename!="")
{
  string fullFileName = "ftp://"+ftpUserName+":"+ftpUserPassword+"@"+ftpIp+"/"+projectId +"/"+filename;
      
  FileStream MyFileStream = new FileStream( fileFullName,FileMode.CreateNew);//出错处
------------------
会提示不支持给定路径的格式。
是不是需要将filestream换成其他?

解决方案 »

  1.   

    Response.Write("<script>window.open(fullFileName)</script>");或者直接用链接
      

  2.   

    LoveCherry:
    文件下载是单独写在一个csharp文件中的。而且要求隐藏文件的地址。
      

  3.   

    哪位兄弟知道?是不是filestream只支持本地?
      

  4.   

    这个类返回的FtpStream,不是FileStream
    FtpStream ftpfs=ftp.OpenFile(filename,GenericRights.Read);
    你先要用ftpfs的Read方法把数据流读入byte[]中
    然后写入FileStream才行
      

  5.   

    LoveCherry:返回的ftpfs的Length属性
    Length <错误: 发生 {System.NotSupportedException} 类型的异常> long
    不知怎么回事?
      

  6.   

    要用buffer不要一下子读取,例子如下,你自己修改:
    string filename="b.rar";
    string fileextname=filename.Split('.')[filename.Split('.').Length-1];
    string DEFAULT_CONTENT_TYPE = "application/unknown";
    RegistryKey regkey,fileextkey;
    string filecontenttype;
    try 
    {                
    regkey=Registry.ClassesRoot;                
    fileextkey=regkey.OpenSubKey(fileextname);                
    filecontenttype=fileextkey.GetValue("Content Type",DEFAULT_CONTENT_TYPE).ToString();
    }
    catch
    {
    filecontenttype=DEFAULT_CONTENT_TYPE;
    }        
    Response.Clear();
    Response.AddHeader("Content-Disposition", "attachment; filename=" + Server.UrlEncode(filename)); 
    Response.ContentType=filecontenttype;

    FtpSupport.FtpConnection conn=new FtpSupport.FtpConnection("localhost",@"ubishanghai\yzhu3","Abcd0.123");
    conn.SetCurrentDirectory("/");
    if(conn.FileExist(filename))
    {
    FtpSupport.FtpStream ftpfs=conn.OpenFile(filename,FtpSupport.GenericRights.Read);
    byte [] buffer=new byte[10240];
    int n=ftpfs.Read(buffer,0,buffer.Length);
    while(n>0)
    {
    Response.BinaryWrite(buffer);
    n=ftpfs.Read(buffer,0,buffer.Length);
    }
    ftpfs.Close();

    }
    }
      

  7.   

    忘记说了需要using Microsoft.Win32;
    我的例子是从注册表读取ContentType然后直接BinaryWrite的
    byte [] buffer=new byte[10240];
    如果你觉得下载慢可以适当增加buffer。