当访问本地机上的ftp(serveU)时,可以获取指定路径下的文件、文件夹;访问远程的ftp时之可以获取指定目录下的文件,不知道是不是ftp服务器的设置问题?
另外,通过list命令获取文件属性(例如-rw-rw-rw-)来判断是否为文件夹,这种方法是否可行?
希望高手指点public string[] getFileList_list(string mask) //获取文件列表
{ if (!logined)
{
login();
} Socket cSocket = createDataSocket(); sendCommand("LIST " + mask); if (!(retValue == 150 || retValue == 125))
{
throw new IOException(reply.Substring(4));
} mes = "";
int iCnt=0;
while (true)
{ int bytes = cSocket.Receive(buffer, buffer.Length, 0);
mes += ASCII.GetString(buffer, 0, bytes); if (bytes < buffer.Length)
{
if (bytes <=0 && ++iCnt == 5)break;
}
else
iCnt = 0;
} char[] seperator = { '\n' };
string[] mess = mes.Split(seperator); cSocket.Close(); readReply(); if (retValue != 226)
{
throw new IOException(reply.Substring(4));
}
return mess; }
另外,通过list命令获取文件属性(例如-rw-rw-rw-)来判断是否为文件夹,这种方法是否可行?
希望高手指点public string[] getFileList_list(string mask) //获取文件列表
{ if (!logined)
{
login();
} Socket cSocket = createDataSocket(); sendCommand("LIST " + mask); if (!(retValue == 150 || retValue == 125))
{
throw new IOException(reply.Substring(4));
} mes = "";
int iCnt=0;
while (true)
{ int bytes = cSocket.Receive(buffer, buffer.Length, 0);
mes += ASCII.GetString(buffer, 0, bytes); if (bytes < buffer.Length)
{
if (bytes <=0 && ++iCnt == 5)break;
}
else
iCnt = 0;
} char[] seperator = { '\n' };
string[] mess = mes.Split(seperator); cSocket.Close(); readReply(); if (retValue != 226)
{
throw new IOException(reply.Substring(4));
}
return mess; }
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货