*******************关于c#编写的ftplibary的问题**************
在使用网上某人编写的ftp的类库的时候,发现一个错误,不知道该如何解决,请大家帮忙看看
附加:我是用这个getfilelist来判断ftp服务器有没有指定名字的文件夹?如果当ftp服务器存在这个文件夹的时候却执行到刚才的地方就出现错误
/// <summary>
/// Return a string array containing the remote directory's file list.
/// </summary>
/// <param name="mask"></param>
/// <returns></returns>
public string[] GetFileList(string mask)
{
if ( !this.loggedin ) this.Login();
Socket cSocket = createDataSocket();
this.sendCommand("NLST " + mask);
if (!(this.resultCode == 150 || this.resultCode == 125)) return null;//throw new FtpException(this.result.Substring(4));
this.message = "";
DateTime timeout = DateTime.Now.AddSeconds(this.timeoutSeconds);
while( timeout > DateTime.Now )
{
int bytes = cSocket.Receive(buffer, buffer.Length, 0);
this.message += ASCII.GetString(buffer, 0, bytes);
if ( bytes < this.buffer.Length ) break;
}
string[] msg = this.message.Replace("\r","").Split('\n');
cSocket.Close();
if ( this.message.IndexOf( "No such file or directory" ) != -1 )
msg = new string[]{};
this.readResponse();----执行到这进入到函数体
if ( this.resultCode != 226 )
msg = new string[]{};
// throw new FtpException(result.Substring(4));
return msg;
}
/// <summary>
///
/// </summary>
private void readResponse()
{
this.message = "";
this.result = this.readLine();---进入函数体
if ( this.result.Length > 3 )
this.resultCode = int.Parse( this.result.Substring(0,3) );
else
this.result = null;
}
/// <summary>
///
/// </summary>
/// <returns></returns>
private string readLine()
{
while(true)
{
this.bytes = clientSocket.Receive( this.buffer, this.buffer.Length, 0 ); ---执行到这里的时候程序就停在这里不动了,估计是未取到数据所以一直被阻塞,谁能帮我解决这个问题,让程序能正确运行
this.message += ASCII.GetString( this.buffer, 0, this.bytes );
if ( this.bytes < this.buffer.Length )
{
break;
}
}
string[] msg = this.message.Split('\n');
if ( this.message.Length > 2 )
this.message = msg[ msg.Length - 2 ];
else
this.message = msg[0];
if ( this.message.Length > 4 && !this.message.Substring(3,1).Equals(" ") ) return this.readLine();
if ( this.verboseDebugging )
{
for(int i = 0; i < msg.Length - 1; i++)
{
Debug.Write( msg[i], "FtpClient" );
}
}
return message;
}