|
#region 文件操作
/// <summary>
/// 获得文件列表
/// </summary>
/// <param name="strMask">文件名的匹配字符串</param>
public string[] Dir(string strMask)
{
if (!bConnected)
{
Connect();
}
Socket socketData = CreateDataSocket();
SendCommand("NLST " + strMask);
if (!(iReplyCode == 150 || iReplyCode == 125 || iReplyCode == 226))
{
throw new IOException(strReply.Substring(4));
}
strMsg = "";
Thread.Sleep(2000);
while (true)
{
int iBytes = socketData.Receive(buffer, buffer.Length, 0);
strMsg += Defaul.GetString(buffer, 0, iBytes);
if (iBytes < buffer.Length)
{
break;
}
}
char[] seperator = { '\n' };
string[] strsFileList = strMsg.Split(seperator);
socketData.Close(); //数据socket关闭时也会有返回码
if (iReplyCode != 226)
{
ReadReply();
if (iReplyCode != 226)
{
throw new IOException(strReply.Substring(4));
}
}
return strsFileList;
}
|
|