Beispiel #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();
                    }
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Get the full path of a given FTP Listing entry
        /// </summary>
        public static void CalculateFullFtpPath(this FtpListItem item, FtpClient client, string path)
        {
            // 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 (client.ServerType == FtpServer.IBMzOSFTP &&
                client.zOSListingRealm != FtpZOSListRealm.Unix)
            {
                // The user might be using GetListing("", FtpListOption.NoPath)
                // or he might be using    GetListing("not_fully_qualified_zOS path")
                // or he might be using    GetListing("'fully_qualified_zOS path'") (note the single quotes)

                // The following examples in the comments assume a current working
                // directory of 'GEEK.'.

                // If it is not a FtpZOSListRealm.Dataset, it must be FtpZOSListRealm.Member*

                // Is caller using FtpListOption.NoPath and CWD to the right place?
                if (path.Length == 0)
                {
                    if (client.zOSListingRealm == FtpZOSListRealm.Dataset)
                    {
                        // Path: ""
                        // Fullname: 'GEEK.PROJECTS.LOADLIB'
                        item.FullName = client.GetWorkingDirectory().TrimEnd('\'') + item.Name + "\'";
                    }
                    else
                    {
                        // Path: ""
                        // Fullname: 'GEEK.PROJECTS.LOADLIB(MYPROG)'
                        item.FullName = client.GetWorkingDirectory().TrimEnd('\'') + "(" + item.Name + ")\'";
                    }
                }
                // Caller is not using FtpListOption.NoPath, so the fullname can be built
                // depending on the listing realm
                else if (path[0] == '\'')
                {
                    if (client.zOSListingRealm == FtpZOSListRealm.Dataset)
                    {
                        // Path: "'GEEK.PROJECTS.LOADLIB'"
                        // Fullname: 'GEEK.PROJECTS.LOADLIB'
                        item.FullName = item.Name;
                    }
                    else
                    {
                        // Path: "'GEEK.PROJECTS.LOADLIB(*)'"
                        // Fullname: 'GEEK.PROJECTS.LOADLIB(MYPROG)'
                        item.FullName = path.Substring(0, path.Length - 4) + "(" + item.Name + ")\'";
                    }
                }
                else
                {
                    if (client.zOSListingRealm == FtpZOSListRealm.Dataset)
                    {
                        // Path: "PROJECTS.LOADLIB"
                        // Fullname: 'GEEK.PROJECTS.LOADLIB'
                        item.FullName = client.GetWorkingDirectory().TrimEnd('\'') + item.Name + '\'';
                    }
                    else
                    {
                        // Path: "PROJECTS.LOADLIB(*)"
                        // Fullname: 'GEEK.PROJECTS.LOADLIB(MYPROG)'
                        item.FullName = client.GetWorkingDirectory().TrimEnd('\'') + path.Substring(0, path.Length - 3) + "(" + item.Name + ")\'";
                    }
                }
                return;
            }
            else if (client.ServerType == FtpServer.OpenVMS &&
                     client.ServerOS == FtpOperatingSystem.VMS)
            {
                // if this is a vax/openvms file listing
                // there are no slashes in the path name
                item.FullName = path + item.Name;
            }
            else
            {
                //this.client.LogStatus(item.Name);

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

                if (path.Length == 0)
                {
                    path = client.GetWorkingDirectory();
                }

                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();
                    }
                }
            }
        }