******如何使用FtpWebRequest对ftp服务器上面的目录进行改名(注意是目录不是文件!)*****

jimu8130 jimu8130 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
比如我的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;
}
...全文
评论 31
收藏 已收藏
分享
返回顶部
jimu8130
C# 111,128 成员 642,536 内容