zoukankan      html  css  js  c++  java
  • 如何使用FtpWebRequest对ftp服务器上面的目录进行改名(注意是目录不是文件!)

    比如我的ftp服务器针对user用户建立了一个目录(名字为0)
    那么我在客户端如何对其改名(改为1)了?
    请大家帮忙提供下正确的代码(最好自己先测试通过!)
    下面是我的部分代码
                URI = @"ftp://"+服务器ip+"/0";
                System.Net.FtpWebRequest ftp = GetRequest(URI);
                //Set request to delete
                ftp.Method = System.Net.WebRequestMethods.Ftp.Rename;
                ftp.RenameTo = "/1";
                try
                {
                    //get response but ignore it
                    string str = GetStringResponse(ftp);///运行到这里会报错!!!
                }
                catch (Exception)
                {
                    return false;
                }

     //Get the basic FtpWebRequest object with the
            //common settings and security
            private FtpWebRequest GetRequest(string URI)
            {
                URI = @"ftp://" + URI;
              
                FtpWebRequest result = (FtpWebRequest)FtpWebRequest.Create(URI);
           
                result.Credentials = GetCredentials();
             
                result.EnableSsl = false;
            
                result.KeepAlive = false;
                // support for passive connections
                result.UsePassive = true;
                return result;
            }
           
            private string GetStringResponse(FtpWebRequest ftp)
            {
                //Get the result, streaming to a string
                string result = "";
                using (FtpWebResponse response = (FtpWebResponse)ftp.GetResponse())
                {
                    long size = response.ContentLength;
                    using (Stream datastream = response.GetResponseStream())
                    {
                        using (StreamReader sr = new StreamReader(datastream, System.Text.Encoding.UTF8))
                        {
                            result = sr.ReadToEnd();
                            sr.Close();
                        }

                        datastream.Close();
                    }

                    response.Close();
                }

                return result;
            }

  • 相关阅读:
    c#文件读取
    asp.net页面缓存学习
    JQuery学习
    如何在asp.net后台调用前台代码
    c#文件操作二
    oracler主键自动增长
    C#委托学习
    小技巧:DIV中显示字符不完整的解决方法
    英文名字的误区及起名方法
    SharePoint 2010 中提供的母版页
  • 原文地址:https://www.cnblogs.com/ocean2000/p/861340.html
Copyright © 2011-2022 走看看