Exemple #1
0
        private Folder GetRemoteFolder(
			string strFolder,
			bool fKeepAlive,
			out string strResponseText )
        {
            if ( !string.IsNullOrEmpty(strFolder) )
                if ( !folderExistsOnServer( strFolder ) )
                {
                    strResponseText = null;
                    return null;
                }

            FtpWebRequest request;
            FtpWebResponse ftpResponse;
            Stream ftpStream;
            for ( int i = 1 ; ; i++ )
                try
                {
                    request = createRequest( strFolder );
                    request.Method = WebRequestMethods.Ftp.ListDirectoryDetails;
                    request.KeepAlive = fKeepAlive && i==1;
                    ftpResponse = (FtpWebResponse)request.GetResponse();
                    ftpStream = ftpResponse.GetResponseStream();
                    break;
                }
                catch ( Exception ex )
                {
                    if ( ex.ToString().IndexOf("(500)")<0 || i>2 )
                        throw ex;
                    Thread.Sleep( i * 500 );
                }

            using( StreamReader sr = new StreamReader(ftpStream,System.Text.Encoding.Default) )
                strResponseText = sr.ReadToEnd();
            ftpStream.Close();
            ftpResponse.Close();

            Folder folder = new Folder(strFolder);
            if ( !string.IsNullOrEmpty( strResponseText ) )
                foreach ( string strLine in strResponseText.Replace( '\r', '\n' ).Split( '\n' ) )
                    if ( strLine.Length!=0 )
                        folder.AddRemoteItem( strFolder, strLine );

            return folder;
        }