*******************关于c#编写的ftplibary的问题**************

kisskiki 2007-08-27 09:51:09
在使用网上某人编写的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;
}
...全文
139 14 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
wanghui0380 2007-08-27
  • 打赏
  • 举报
回复
恩,ftp有被动和主动的区别
通常在文件列表停止的ftp,都需要使用被动模式来连接

看你的那个代码似乎是主动模式的代码,你需要另外去写被动模式的代码
whw123456 2007-08-27
  • 打赏
  • 举报
回复
友情帮顶·
kisskiki 2007-08-27
  • 打赏
  • 举报
回复
to jame:
虽然不停在那里,但是老是超时也不行啊
kisskiki 2007-08-27
  • 打赏
  • 举报
回复
行,我看看设置后能否运行正常
jamesfay 2007-08-27
  • 打赏
  • 举报
回复
2.0的话设定Socket.ReceiveTimeout 和SendTimeout

1.1以上需要放在一个线程里面做,然后判断timeout
kisskiki 2007-08-27
  • 打赏
  • 举报
回复
没人来看看么?
kisskiki 2007-08-27
  • 打赏
  • 举报
回复
大家帮忙看看啊
w275221545c 2007-08-27
  • 打赏
  • 举报
回复
先顶了再说
honey52570 2007-08-27
  • 打赏
  • 举报
回复
sf
kisskiki 2007-08-27
  • 打赏
  • 举报
回复
又没人看了么?
kisskiki 2007-08-27
  • 打赏
  • 举报
回复
to jamesfay:
你难道时候说模拟cuteftp发送命令?
kisskiki 2007-08-27
  • 打赏
  • 举报
回复
to remex:
你给的那个代码早就用过了,不知道你自己用过没有?我用的时候用它传输gif文件的时候非常慢
不知道你怎么解决这个问题,特别是一次传输至少1000个文件!

to wanghui:
啊,我现在并没有传输文件或者怎么样,我仅仅就是想获取ftp服务器上面有没有指定名称的文件夹。你说的我并不是很清楚,能否给出你的代码以帮助我理解?
REMEX1980 2007-08-27
  • 打赏
  • 举报
回复
参考这个源代码:

http://bbs.msproject.cn/default.aspx?g=posts&t=233


------------------------------------------------------------------------------------------
庆祝MSProject开源技术( http://bbs.msproject.cn/ )注册会员过1000
jamesfay 2007-08-27
  • 打赏
  • 举报
回复
你用cuteftp连接上去看看cuteftp用了哪些命令?

62,243

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

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