Example #1
0
        /// <summary>
        /// Get the full path of a given FTP Listing entry
        /// </summary>
        public static void CalculateFullFtpPath(this FtpListItem item, FtpClient client, string path, bool isVMS)
        {
            // EXIT IF NO DIR PATH PROVIDED
            if (path == null)
            {
                // check if the path is absolute
                if (IsAbsolutePath(item.Name))
                {
                    item.FullName = item.Name;
                    item.Name     = item.Name.GetFtpFileName();
                }

                return;
            }


            // ONLY IF DIR PATH PROVIDED

            // if this is a vax/openvms file listing
            // there are no slashes in the path name
            if (isVMS)
            {
                item.FullName = path + item.Name;
            }
            else
            {
                //this.client.LogStatus(item.Name);

                // remove globbing/wildcard from path
                if (path.GetFtpFileName().Contains("*"))
                {
                    path = path.GetFtpDirectoryName();
                }

                if (item.Name != null)
                {
                    // absolute path? then ignore the path input to this method.
                    if (IsAbsolutePath(item.Name))
                    {
                        item.FullName = item.Name;
                        item.Name     = item.Name.GetFtpFileName();
                    }
                    else if (path != null)
                    {
                        item.FullName = path.GetFtpPath(item.Name);                         //.GetFtpPathWithoutGlob();
                    }
                    else
                    {
                        client.LogStatus(FtpTraceLevel.Warn, "Couldn't determine the full path of this object: " +
                                         Environment.NewLine + item.ToString());
                    }
                }


                // if a link target is set and it doesn't include an absolute path
                // then try to resolve it.
                if (item.LinkTarget != null && !item.LinkTarget.StartsWith("/"))
                {
                    if (item.LinkTarget.StartsWith("./"))
                    {
                        item.LinkTarget = path.GetFtpPath(item.LinkTarget.Remove(0, 2)).Trim();
                    }
                    else
                    {
                        item.LinkTarget = path.GetFtpPath(item.LinkTarget).Trim();
                    }
                }
            }
        }