检查Ftp上是否存在,用FtpFindFirstFile会出错?如果用FtpOpenFile来检查文件是否存在, 如果没有使用过FtpGetFile,是正确的, 但是使用了FtpGetFile后, 把文件删除了用FtpOpenFile还是成功.
正确检查FTP上文件是否存在要用什么?

解决方案 »

  1.   

    检测FtpWebResponse.StatusCode的状态
      

  2.   

    RFC 2389 FEATURE 命令获知服务器支持 SIZE, MDTM 命令后, 用 SIZE 或者 MDTM 来获取文件信息否则纯粹 RFC 959 则只能列表了.
      

  3.   

    private bool FileRequest(string file)
            {
                FtpWebRequest ftp = (FtpWebRequest)WebRequest.Create(file);
                ftp.Method = WebRequestMethods.Ftp.GetFileSize;
                try
                {
                    FtpWebResponse ftpresponse = (FtpWebResponse)ftp.GetResponse();
                    return true;
                }
                catch (WebException ex)
                {
                    FtpWebResponse wr = (FtpWebResponse)ex.Response;
                    return false;
                }
                catch
                {
                    return false;
                }
            }MessageBox.Show(FileRequest("ftp://ftp用户:密码@ftp地址/web/d.txt").ToString());
      

  4.   

    FtpFindFirstFile 支持wince的調用
      

  5.   


    好像FtpFindFirstFile返回的是一个文件夹,不是一个文件,那怎么检查一个文件存在呢?