请问FTP里有没有类似Directory.CreateDirectory的方法 任务需要一次性建多级子目录,如果需要一级一级建有点麻烦,不知道哪位仁兄能提供下方案或实现上述要求的,先谢了. 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 可以去codeproject等网站搜下ftp的类库,这样你就不用去担心这些问题了。 应该有的,不过你可先做一个简单的程序试不就明白了。同时到codeproject上找找 你去找个ftpclient.cs的类用一用.里边提供了很多方法.封装的不错. 我不想调用未开源的类,而且那个我看过也没有我想要的.我现在需要判断一下目录是否存在,如不存在则建目录(可能多级),改了下面两个方法用了下,感觉还是很有问题,只能建一级目录不说,那个判断目录是否存在的第一次好用,第二次就不在根目录下判断而跳到下一级去了.../// 检查文件是否存在 /// </summary> /// <param name="parentPath">父目录</param> /// <param name="name">文件名</param> /// <returns></returns> protected bool CheckFileOrPath(string parentPath, string fileName) { //检查一下日期目录是否存在 FtpWebRequest req = (FtpWebRequest)FtpWebRequest.Create(config.GetFtpUri(parentPath)); req.Credentials = config.Credentials; req.Method = WebRequestMethods.Ftp.ListDirectoryDetails; Stream stream = req.GetResponse().GetResponseStream(); using (StreamReader sr = new StreamReader(stream)) { string line = sr.ReadLine(); while (!string.IsNullOrEmpty(line)) { GroupCollection gc = regexName.Match(line).Groups; if (gc.Count != 1) { throw new ApplicationException("FTP 返回的字串格式不正确"); } string path = gc[0].Value; if (path == fileName) { return true; } line = sr.ReadLine(); } } return false; } protected void CreatePath(string parentPath, string name) { FtpWebRequest req = (FtpWebRequest)FtpWebRequest.Create(config.GetFtpUri(string.Format("{0}/{1}",parentPath,name))); req.Credentials = config.Credentials; req.Method = WebRequestMethods.Ftp.MakeDirectory; req.GetResponse(); } 建目录本来就是一级一级的建立!baidu一下有很多FTP相关的 C#中的委托机制有何作用 KeyDown的问题 winform 窗口随系统启动 用X关闭一个窗口,弹出提示:确定关闭,取消不关闭。各位大虾,怎么实现? TabControl的问题 WPF开发当中遇到这样的异常 紧急提问,看不懂一个需求,关于C#下refactor的,着急,在线等 急!!怎么刷新listBox? 为什么在工具栏中找不到OleDbDataAdapter/SqlDataAdapter控件呢? 从DELPHI转过来学C#难不难 sql server 在C#不能够连接 asp.net + c#的简单问题
同时到codeproject上找找
/// 检查文件是否存在
/// </summary>
/// <param name="parentPath">父目录</param>
/// <param name="name">文件名</param>
/// <returns></returns>
protected bool CheckFileOrPath(string parentPath, string fileName)
{
//检查一下日期目录是否存在
FtpWebRequest req = (FtpWebRequest)FtpWebRequest.Create(config.GetFtpUri(parentPath));
req.Credentials = config.Credentials;
req.Method = WebRequestMethods.Ftp.ListDirectoryDetails; Stream stream = req.GetResponse().GetResponseStream(); using (StreamReader sr = new StreamReader(stream))
{
string line = sr.ReadLine();
while (!string.IsNullOrEmpty(line))
{
GroupCollection gc = regexName.Match(line).Groups;
if (gc.Count != 1)
{
throw new ApplicationException("FTP 返回的字串格式不正确");
} string path = gc[0].Value;
if (path == fileName)
{
return true;
} line = sr.ReadLine();
}
} return false; } protected void CreatePath(string parentPath, string name)
{
FtpWebRequest req = (FtpWebRequest)FtpWebRequest.Create(config.GetFtpUri(string.Format("{0}/{1}",parentPath,name)));
req.Credentials = config.Credentials;
req.Method = WebRequestMethods.Ftp.MakeDirectory;
req.GetResponse();
}
baidu一下有很多FTP相关的