Example #1
0
        private String[] GetSubDirs(string path)
        {
            string ftpfullpath = "ftp://" + site.host + path;
            ArrayList files = new ArrayList();
            lock (FtpSite.LockInstance())
            {

                ftp = (FtpWebRequest)FtpWebRequest.Create(ftpfullpath);

                ftp.Credentials = new NetworkCredential(site.username, site.pwd);
                //userid and password for the ftp server to given

                ftp.KeepAlive = true;
                ftp.UseBinary = true;

                ftp.Method = WebRequestMethods.Ftp.ListDirectoryDetails;

                FtpWebResponse ftpResponse = (FtpWebResponse)ftp.GetResponse();
                Stream responseStream = ftpResponse.GetResponseStream();

                string strFile;
                using (StreamReader reader = new StreamReader(responseStream))
                {
                    while ((strFile = reader.ReadLine()) != null)
                    {
                        FtpFileInfo fInfo = new FtpFileInfo(strFile, site.type);
                        if (fInfo.isDir && fInfo.name != "." && fInfo.name != "..")
                        {
                            files.Add(fInfo.name);
                        }
                    }

                }

                ftpResponse.Close();
            }

            return (String[])files.ToArray(typeof(String));
        }
        /**
         * Get the files.
         */
        private FtpFileInfo[] GetFiles(KexplorerFtpNode knode)
        {
            ArrayList files = new ArrayList();
            string ftpfullpath = "ftp://" + kNode.Site.host +knode.Path;
            FtpWebResponse ftpResponse = null;
            FtpWebRequest ftp = null;
            try
            {

                ftp = (FtpWebRequest)FtpWebRequest.Create(ftpfullpath);

                ftp.Credentials = new NetworkCredential(kNode.Site.username, kNode.Site.pwd);
                //userid and password for the ftp server to given

                ftp.KeepAlive = true;
                ftp.UseBinary = true;

                ftp.Method = WebRequestMethods.Ftp.ListDirectoryDetails;

                ftpResponse = (FtpWebResponse)ftp.GetResponse();

                Stream responseStream = null;

                responseStream = ftpResponse.GetResponseStream();

                string strFile = null;

                try
                {
                    StreamReader reader = new StreamReader(responseStream);
                    while (true)
                    {
                        strFile = null;
                        try
                        {
                            strFile = reader.ReadLine();
                        }
                        catch (IOException e)
                        {
                            break;
                        }

                        if (strFile != null)
                        {
                            FtpFileInfo newFileInfo = new FtpFileInfo(strFile, kNode.Site.type);
                            if ( !newFileInfo.isDir )
                            {

                                files.Add( newFileInfo );

                            }
                        }
                        else
                        {
                            break;
                        }
                    }
                }
                catch (Exception e)
                {
                    String x = e.Message;

                }

                try
                {
                    ftpResponse.Close();
                }
                catch (Exception e)
                {
                }
            }

            catch (WebException e)
            {

                return null;
            }
            finally
            {
                if (ftpResponse != null)
                {
                    ftpResponse.Close();
                }
            }

            return (FtpFileInfo[])files.ToArray(typeof(FtpFileInfo));
        }
Example #3
0
        //-----------------------------------------------------------------------------//
        /// <summary>
        /// Job one is setup the ftp connection.
        /// 
        /// KCS: 2/19/08 - Drive nodes are created by the main controller, because we know we always
        /// want them.  This insures they're created in alphabetical order. etc.
        /// </summary>
        private IWorkUnit DoJobOne()
        {
            IWorkUnit nextWorkUnit = null;

            if ( this.ftp == null && !this.stop )
            {

                try
                {
                    ArrayList files = new ArrayList();
                    lock (FtpSite.LockInstance())
                    {
                        currentPath = site.targetFolder + "/";
                        string ftpfullpath = "ftp://" + site.host + currentPath;

                        ftp = (FtpWebRequest)FtpWebRequest.Create(ftpfullpath);

                        ftp.Credentials = new NetworkCredential(site.username, site.pwd);
                        //userid and password for the ftp server to given

                        ftp.KeepAlive = true;
                        ftp.UseBinary = true;

                        ftp.Method = WebRequestMethods.Ftp.ListDirectoryDetails;

                        FtpWebResponse ftpResponse = (FtpWebResponse)ftp.GetResponse();
                        Stream responseStream = ftpResponse.GetResponseStream();

                        string strFile;
                        using (StreamReader reader = new StreamReader(responseStream))
                        {
                            while ((strFile = reader.ReadLine()) != null)
                            {
                                FtpFileInfo fInfo = new FtpFileInfo(strFile, site.type);
                                if (fInfo.isDir && fInfo.name != "." && fInfo.name != ".." )
                                {
                                    files.Add(fInfo.name);
                                }
                            }

                        }

                        ftpResponse.Close();
                    }

                    this.subDirs = (String[])files.ToArray(typeof(String));

                    if (this.subDirs != null && this.subDirs.Length > 0 && !this.stop)
                    {

                        try
                        {

                            this.guiFlagger.SignalBeginGUI();

                            this.form.MainForm.Invoke(new InvokeDelegate(this.AddDirectories));

                        }
                        finally
                        {

                            this.guiFlagger.SignalEndGUI();
                        }

                        // If there were sub-dirs, then, Job 3 should load each one.
                        nextWorkUnit = this;
                    }

                }
                catch (Exception e)
                {
                    MessageBox.Show("Exception setting up FTP: " + e.Message);

                }
                finally
                {

                }

            }
            return nextWorkUnit;
        }
Example #4
0
        private String[] GetSubDirs(string path, int countdown)
        {
            if (countdown == 0)
            {
                return new String[0];
            }
            if (path.Contains("HNI/5.4"))
            {
                String x = path;
                Console.WriteLine(x);
            }

            ArrayList files = new ArrayList();
            string ftpfullpath = "ftp://" + site.host + path;
            FtpWebResponse ftpResponse = null;
            try
            {

                    ftp = (FtpWebRequest)FtpWebRequest.Create(ftpfullpath);

                    ftp.Credentials = new NetworkCredential(site.username, site.pwd);
                    //userid and password for the ftp server to given

                    ftp.KeepAlive = true;
                    ftp.UseBinary = true;

                    ftp.Method = WebRequestMethods.Ftp.ListDirectoryDetails;

                    ftpResponse = (FtpWebResponse)ftp.GetResponse();

                Stream responseStream = null;

                    responseStream = ftpResponse.GetResponseStream();

                string strFile = null;

                try
                {
                    StreamReader reader = new StreamReader(responseStream);
                    while (true)
                    {
                        strFile = null;
                        try
                        {
                            strFile = reader.ReadLine();
                        }
                        catch (IOException e)
                        {
                            break;
                        }

                        if (strFile != null)
                        {
                            FtpFileInfo fInfo = new FtpFileInfo(strFile, site.type);
                            if (fInfo.isDir)
                            {
                                if (!(fInfo.name.Equals(".") || fInfo.name.Equals("..")))
                                {
                                    files.Add(fInfo.name);
                                }
                            }
                        }
                        else
                        {
                            break;
                        }
                    }
                }
                catch (Exception e)
                {
                    String x = e.Message;
                    if (x.Contains("550"))
                    {

                        Thread.Sleep(200);
                        try
                        {
                            ftpResponse.Close();
                        }
                        catch (Exception) { }
                        return GetSubDirs(path, --countdown);

                    }
                }

                try
                {
                    ftpResponse.Close();
                }
                catch (Exception e)
                {
                }
            }

            catch (WebException e)
            {
                String x = e.Message;
                Console.WriteLine(x);
                Thread.Sleep(50);
                return null;
            }
            finally
            {
                if (ftpResponse != null)
                {
                    ftpResponse.Close();
                }
            }

            return (String[])files.ToArray(typeof(String));
        }