C# 判断ftp上目录是否存在
C#控制ftp,需要完成这样一个功能:判断一个目录是否存在,不存在则创建该目录,存在则不创建。...
C# 控制ftp, 需要完成这样一个功能: 判断一个目录是否存在,不存在则创建该目录,存在则不创建。
展开
1个回答
展开全部
FtpWebRequest
frequest
=
FtpWebRequest.Create("
ftp://guoming.daya.com:1212/test")
as
FtpWebRequest;
frequest.Credentials
=
new
NetworkCredential("用户名",
"密码");
frequest.Method
=
WebRequestMethods.Ftp.ListDirectory;
try
{
FtpWebResponse
response
=
frequest.GetResponse()
as
FtpWebResponse;
}
catch
{
Console.WriteLine("目录不存在");
}
答案补充
重复以上操作就可以了啊
FtpWebRequest
frequest
=
FtpWebRequest.Create("ftp://guoming.daya.com:1212/test/test")
as
FtpWebRequest;
frequest.Credentials
=
new
NetworkCredential("用户名",
"密码");
frequest.Method
=
WebRequestMethods.Ftp.MakeDirectory;
try
{
FtpWebResponse
response
=
frequest.GetResponse()
as
FtpWebResponse;
}
catch
{
}
答案补充
FtpWebRequest
frequest
=
FtpWebRequest.Create("ftp://guoming.daya.com:1212/test/test/test")
as
FtpWebRequest;
frequest.Credentials
=
new
NetworkCredential("用户名",
"密码");
frequest.Method
=
WebRequestMethods.Ftp.MakeDirectory;
try
{
FtpWebResponse
response
=
frequest.GetResponse()
as
FtpWebResponse;
}
catch
{
}
答案补充
暂时没有好的解决方法。
frequest
=
FtpWebRequest.Create("
ftp://guoming.daya.com:1212/test")
as
FtpWebRequest;
frequest.Credentials
=
new
NetworkCredential("用户名",
"密码");
frequest.Method
=
WebRequestMethods.Ftp.ListDirectory;
try
{
FtpWebResponse
response
=
frequest.GetResponse()
as
FtpWebResponse;
}
catch
{
Console.WriteLine("目录不存在");
}
答案补充
重复以上操作就可以了啊
FtpWebRequest
frequest
=
FtpWebRequest.Create("ftp://guoming.daya.com:1212/test/test")
as
FtpWebRequest;
frequest.Credentials
=
new
NetworkCredential("用户名",
"密码");
frequest.Method
=
WebRequestMethods.Ftp.MakeDirectory;
try
{
FtpWebResponse
response
=
frequest.GetResponse()
as
FtpWebResponse;
}
catch
{
}
答案补充
FtpWebRequest
frequest
=
FtpWebRequest.Create("ftp://guoming.daya.com:1212/test/test/test")
as
FtpWebRequest;
frequest.Credentials
=
new
NetworkCredential("用户名",
"密码");
frequest.Method
=
WebRequestMethods.Ftp.MakeDirectory;
try
{
FtpWebResponse
response
=
frequest.GetResponse()
as
FtpWebResponse;
}
catch
{
}
答案补充
暂时没有好的解决方法。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询