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

jimu8130 2007-08-18 05:49:33
比如我的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;
}
...全文
545 31 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
31 条回复
切换为时间正序
请发表友善的回复…
发表回复
jimu8130 2007-08-20
  • 打赏
  • 举报
回复
to civanx:
恩,那太感谢你了。
civanx 2007-08-20
  • 打赏
  • 举报
回复
看上去是直接客户异常,而不是FTP返回的错误信息了?

暂时没调试环境,

晚上回去给你看看
jimu8130 2007-08-20
  • 打赏
  • 举报
回复
to civanx:
你可以看看这个帖子
http://community.csdn.net/Expert/topic/5716/5716924.xml?temp=.7247583
jimu8130 2007-08-20
  • 打赏
  • 举报
回复
to jinglecat:
我的机器是xp系统,测试的时候我特地将服务器(本机)建立了一个文件夹,然后跑了上面那段代码,结果
ftp.Method = System.Net.WebRequestMethods.Ftp.Rename;
ftp.RenameTo = target;
try
{
//get response but ignore it
string str = GetStringResponse(ftp);----运行到这里的时候出现这个错误 (_COMPlusExceptionCode = 0xe0434f4d)
用户密码肯定不会错误,因为能获取到相应路径的ftpwebrequest。至于权限的话,我在xp系统下面已经取消只读的沟选,不过看上去没有用,我每次看文件夹的属性结果仍然是只读
civanx 2007-08-20
  • 打赏
  • 举报
回复
ftp.RenameTo = "1";

看看
civanx 2007-08-20
  • 打赏
  • 举报
回复
To jimu8130:

重命名文件夹和文件操作一样,看我在这个原代码的应用吧!

http://bbs.msproject.cn/default.aspx?g=posts&t=233



--------------------------------------------------------
欢迎大家到http://bbs.msproject.cn/上坐坐
civanx 2007-08-20
  • 打赏
  • 举报
回复
我指错误详细信息
civanx 2007-08-20
  • 打赏
  • 举报
回复
具体什么错误?
jimu8130 2007-08-20
  • 打赏
  • 举报
回复
◎civanx:
不知道你看过我的问题及其说明了么?
-------------------------
比如我的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;
}
civanx 2007-08-20
  • 打赏
  • 举报
回复
WebRequestMethods.Ftp.Rename:

Represents the FTP RENAME protocol method that renames a directory.

试试这个,告诉我结果
jimu8130 2007-08-20
  • 打赏
  • 举报
回复
to rczjp:
fso?不过我的程序是一个windows服务,利用ftp和远端机器联系
civanx 2007-08-20
  • 打赏
  • 举报
回复
我看看,
jimu8130 2007-08-20
  • 打赏
  • 举报
回复
to xcmsp:
不知道你有没有仔细看你给出的网页,上面改名是标题是改文件名称而不是目录的名字!
rczjp 2007-08-20
  • 打赏
  • 举报
回复
有一点,我上传成功后ftp服务器的文件夹就是只读属性,怎么使其上传后的文件夹去掉只读属性?
----------------
FSO可以修改属性的吧
jimu8130 2007-08-20
  • 打赏
  • 举报
回复
to xcmsp:
这个东西我看过了,并不能解决我现在的问题,不知道你有没有解决办法?
xcmsp 2007-08-20
  • 打赏
  • 举报
回复

参考代码:

http://bbs.msproject.cn/default.aspx?g=posts&t=233
jimu8130 2007-08-20
  • 打赏
  • 举报
回复
谁来帮帮我啊
xiaoliangwh 2007-08-20
  • 打赏
  • 举报
回复
up
jimu8130 2007-08-20
  • 打赏
  • 举报
回复
现在加问个问题,是使用ftpwebrequest进行上传快了?还是使用wininet.dll进行ftp上传快了?

jimu8130 2007-08-20
  • 打赏
  • 举报
回复
有没有其他人提出建议的?
加载更多回复(11)