ftp 如何 创建 目录?!!!!!!!!!!!!!!!!!!!!!!!!长了吧

youcunzai 2010-10-13 03:55:19
ftp.ListDir();//返回了所有的文件名 10 01 xyz/r
ftp.ChangeDir("xyz");//总出错!!!

网上都是方法;但是例子没有 就是如何改变的例子没有;
我直接写文件夹的名称 总是报错!!头大啊
...全文
144 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
youcunzai 2010-10-13
  • 打赏
  • 举报
回复
晕倒 现在测试 有可以了;是不是别人在使用的原因
sweetqueen1 2010-10-13
  • 打赏
  • 举报
回复

//例:网络文件夹:为InputPath
//InputPath="//empr/Data/Info/File/",
//InputFileName=this.FUpload.FileName.ToString();fupload为上传文件控件
//InputTotalPath=InputPath+InputFileName;
protected string FileUpload()
{
if (this.FUpload.HasFile)
{
inputTotalPath = inputPath + this.FUpload.FileName.ToString();
if (Files.IsDirectoryExists(inputPath))
{
this.IsExistsUp(inputTotalPath, inputPath, this.FUpload.FileName);
}
else
{
Files.CreateDirectory(inputPath);
this.IsExistsUp(inputTotalPath, inputPath, this.FUpload.FileName);
}
}
}

#region IsExistsUp 檢測文件並上傳
protected void IsExistsUp(string InputTotalPath, string InputPath, string InputFileName)
{
try
{
if (Files.IsFileExists(InputTotalPath))
{
Files.ReNameFile(InputPath, InputFileName);//檢測源文件存在,則重命名
this.FUpload.SaveAs(InputTotalPath);
}
else
{
this.FUpload.SaveAs(InputTotalPath);
}
}
catch (Exception ex)
{
MessageBox.Show(Page, ex.Message);
}
}
#endregion


files.cs文件

#region 目录是否存在
public static Boolean IsDirectoryExists(string InputPath)
{
Boolean strFlag = false;
try
{
if (InputPath.Length > 0)
{
strFlag = Directory.Exists(InputPath);
}
}
catch (Exception ex)
{
strEx = ex.Message;
}
return strFlag;
}
#endregion
#region 创建文件目录
public static Boolean CreateDirectory(string InputPath)
{
Boolean strFlag = false;
try
{
if (!Directory.Exists(InputPath))
{
Directory.CreateDirectory(InputPath);
strFlag = true;
}
}
catch (Exception ex)
{
strEx = ex.Message;
}
return strFlag;
}
#endregion

#region 文件是否存在
public static Boolean IsFileExists(string InputPath)
{
Boolean strFlag = false;
try
{
strFlag = File.Exists(InputPath);
}
catch (Exception ex)
{
strEx = ex.Message;
}
return strFlag;
}
#endregion
#region 重命名(替換舊文件名)
/// <summary>
/// 如存在,則重命名舊文件,再上傳新文件
/// </summary>
public static void ReNameFile(string path, string filename)
{
string path1 = path + filename;
string[] filepath = Directory.GetFiles(path);
foreach (string file in filepath)
{
if (file.ToString().Trim() == path1.ToString().Trim())
{
string time = GetUploadDateTime();
string[] strArray = file.Split(new char[] { '.' });
string str1 = strArray[0].ToString();
string str2 = strArray[1].ToString();
string newfilename = str1 + time + "." + str2;
System.IO.File.Move(file, newfilename);
break;
}
}
}
#endregion
#region 返回文件日期名
public static string GetUploadDateTime()
{
string strMonth = "";
string strDay = "";
string strHour = "";
string strMinute = "";
string strSecond = "";
string strResult = "";
try
{
//Month
switch (DateTime.Now.Month)
{
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
case 8:
case 9:
strMonth = "0" + DateTime.Now.Month ;
break;
default:
strMonth = DateTime.Now.Month.ToString ();
break;
}
//Day
switch (DateTime.Now.Day)
{
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
case 8:
case 9:
strDay = "0" + DateTime.Now.Day;
break;
default:
strDay = DateTime.Now.Day.ToString();
break;
}
//Hour
switch (DateTime.Now.Hour)
{
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
case 8:
case 9:
strHour = "0" + DateTime.Now.Hour;
break;
default:
strHour = DateTime.Now.Hour.ToString();
break;
}
//Minute
switch (DateTime.Now.Minute)
{
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
case 8:
case 9:
strMinute = "0" + DateTime.Now.Minute;
break;
default:
strMinute = DateTime.Now.Minute.ToString();
break;
}
//Second
switch (DateTime.Now.Second)
{
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
case 8:
case 9:
strSecond = "0" + DateTime.Now.Second;
break;
default:
strSecond = DateTime.Now.Second.ToString();
break;
}
strResult = DateTime.Now.Year + strMonth + strDay + strHour + strMinute + strSecond;
}
catch (Exception ex)
{
strEx = ex.Message;
}
return strResult;
}
#endregion

#region 返回文件名称
public static string GetFileName(string InputPath)
{
string strTotalPath = "";
string strResult = "";
try
{
strTotalPath = InputPath.ToUpper ().Replace(@"\", "/").ToString();
if (strTotalPath.Length > 0)
{
Start = strTotalPath.LastIndexOf("/", strTotalPath.Length) + 1;
Length = strTotalPath.Length - Start;
strResult = strTotalPath.Substring(Start, Length);
}
}
catch (Exception ex)
{
strEx = ex.Message;
}
return strResult;
}
#endregion


youcunzai 2010-10-13
  • 打赏
  • 举报
回复
你没明白!
我需要的只在ftp上创建,而不是本地!
langxian_1129 2010-10-13
  • 打赏
  • 举报
回复
用C#自带的File类创建
//创建目录
private void CreateDirtory(string path)
{
if(!File.Exists(path))
{
string [] dirArray = path.Split('\\');
string temp = string.Empty;
for(int i = 0;i<dirArray.Length - 1;i++)
{
temp += dirArray[i].Trim() + "\\";
if(!Directory.Exists(temp))
Directory.CreateDirectory(temp);
}
}
}

110,577

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧