This project is read-only.

GetListing fails enumerating CornerStone MFT server with virtual folders

Dec 4, 2013 at 2:51 PM
Edited Dec 4, 2013 at 11:20 PM
Hi, Thanks for the look. I am connecting to a SRT CornerStone MFT site. The FTP site has virtual folders defined. These folder show up in any FTP client, but your GetListing fails to show the folders ( I get the . & .. folders as well as local folders ) but no Virtual folders.

There are 4 virtual folders defined, one of which this account does not have access to.
I am not sure if the enumeration dies at the folder in which there is no access, or just skips them all.


Here is the code ( used your example )
    public static void GetListing()
    {
        using (FtpClient conn = new FtpClient()) {
            conn.Host = "ftpsite";
            conn.Credentials = new NetworkCredential("ftpuser", "ftppass");
            conn.Credentials.Domain = "domX";
            conn.SocketKeepAlive = true;
            string remoteSystemType = conn.SystemType;               
            conn.DataConnectionType = FtpDataConnectionType.AutoPassive;
            string testfolder = conn.GetWorkingDirectory();

            foreach (FtpListItem item in conn.GetListing(testfolder,FtpListOption.AllFiles))
            {

                switch (item.Type) {
                    case FtpFileSystemObjectType.Directory:
                        Console.WriteLine(item.FullName);
                        break;
                    case FtpFileSystemObjectType.File:
                        Console.WriteLine(item.FullName);
                        break;
                    case FtpFileSystemObjectType.Link:
                        // derefernece symbolic links
                        if (item.LinkTarget != null) {
                            // see the DereferenceLink() example
                            // for more details about resolving links.
                            item.LinkObject = conn.DereferenceLink(item);

                            if (item.LinkObject != null) {
                                Console.WriteLine(item.FullName);
                                // switch (item.LinkObject.Type)...
                            }
                        }
                        break;
                }
            }

        }
    }

Here is the trace.

220 Cornerstone MFT 9.10.1594 Ready.
USER dwgmgr_windsor
331 User name okay, need password.
PASS <omitted>
230-Welcome dwgmgr_windsor from 10.162.15.75. You are now logged in to the Alsto
m Power Inc FTP server.
230 User logged in, proceed.
FEAT
211-Extensions Supported
COMB
MLST type*;size*;modify*;create*;perm*;
SIZE
MDTM
MFMT
MFCT
EPRT
EPSV
XCRC
REST STREAM
DQTA
211 End
Text encoding: System.Text.ASCIIEncoding
SYST
215 UNIX Type: L8
PWD
257 "/srtFtpData/winvaultftp/dwgmgr_windsor/" is current directory.
PWD
257 "/srtFtpData/winvaultftp/dwgmgr_windsor/" is current directory.
TYPE I
200 Type set to I.
EPSV
229 Entering Extended Passive Mode (|||4781|)
MLSD /srtFtpData/winvaultftp/dwgmgr_windsor
150 File status okay; about to open data connection.
type=dir;size=512;modify=20131204142141;create=20090205141816;perm=cel; .
type=dir;size=512;modify=20131204142141;create=20090205141816;perm=cel; ..
type=dir;size=512;modify=20131204142138;create=20131204142138;perm=cel; me test
type=dir;size=512;modify=20131204142131;create=20131204142131;perm=cel; testme
226 Closing data connection. Transferred 312 bytes.
Disposing FtpSocketStream...
/srtFtpData/winvaultftp/dwgmgr_windsor/.
/srtFtpData/winvaultftp/dwgmgr_windsor/..
/srtFtpData/winvaultftp/dwgmgr_windsor/me test
/srtFtpData/winvaultftp/dwgmgr_windsor/testme
Disposing FtpClient object...
QUIT
221 Session Ended. Downloaded 0KB, Uploaded 0KB. Goodbye dwgmgr_windsor from 10.
162.15.75.
Disposing FtpSocketStream...

Here is the response from a XP FTP command.

G:>ftp winvaultftp
Connected to winvaultftp.dom3.ad.sys.
220 Cornerstone MFT 9.10.1594 Ready.
User (winvaultftp.dom3.ad.sys:(none)): dwgmgr_windsor
331 User name okay, need password.
Password:
230-Welcome dwgmgr_windsor from 10.162.15.75. You are now logged in to the Alsto
m Power Inc FTP server.
230 User logged in, proceed.
ftp> dir
200 PORT command successful.
150 File status okay; about to open data connection.
drw-rw-rwx 1 dwgmgr_windsor dwgmgr_windsor 512 Dec 04 09:21 .
drw-rw-rwx 1 dwgmgr_windsor dwgmgr_windsor 512 Dec 04 09:21 ..
drw-rw-rwx 1 dwgmgr_windsor dwgmgr_windsor 512 Dec 04 09:21 me test
drw-rw-rwx 1 dwgmgr_windsor dwgmgr_windsor 512 Dec 04 09:21 testme
drw-rw---- 1 dwgmgr_windsor dwgmgr_windsor 512 Oct 11 14:45 HRSGDrawVau
lt
drw-rw---- 1 dwgmgr_windsor dwgmgr_windsor 512 Dec 02 08:28 UPBDrawVaul
t
drw-rw---- 1 dwgmgr_windsor dwgmgr_windsor 512 Dec 02 08:28 UPBImageVau
lt
226 Closing data connection. Transferred 551 bytes.
ftp: 551 bytes received in 0.03Seconds 17.22Kbytes/sec.
ftp>

One half a step from success .....

Any suggestions ?

Thank you !!!!
Coordinator
Dec 4, 2013 at 2:55 PM
I don't see any problem here. Is there a specific error or what? From the code and the transaction log, it looks like the code behaved exactly as it was supposed to. The only suspicious thing I see there is that it parse "." and ".." which it's typically supposed to ignore.
Coordinator
Dec 4, 2013 at 2:56 PM
Ah, I see, you say some folders aren't being listed. I'm not sure why they're not, what's shown to System.Net.FtpClient when MLSD, LIST or NLST are executed is controlled by the server. Have you verified the same behavior with other FTP clients?
Coordinator
Dec 4, 2013 at 2:58 PM
This is all the server is sending:
MLSD /srtFtpData/winvaultftp/dwgmgr_windsor
150 File status okay; about to open data connection.
type=dir;size=512;modify=20131204142141;create=20090205141816;perm=cel; .
type=dir;size=512;modify=20131204142141;create=20090205141816;perm=cel; ..
type=dir;size=512;modify=20131204142138;create=20131204142138;perm=cel; me test
type=dir;size=512;modify=20131204142131;create=20131204142131;perm=cel; testme
We need some more debugging information, perhaps a transaction log from one of the other clients that you say is working. Maybe they have a feature to log the commands they are executing.
Dec 4, 2013 at 2:58 PM
Wow, now that's support !!!!
All other FTP clients seem to handle it.
Coordinator
Dec 4, 2013 at 3:01 PM
Try appending an asterisk to the end of your GetListing() call and try GetListing("/path", FtpListOptions.ForceList | FtpListOption.AllFiles). It may be that the server's implementation of the MLSD command omits the virtual directories. The second example you posted with the cli ftp client returned a unix long listing which tells me it executed LIST instead of MLSD.
Coordinator
Dec 4, 2013 at 3:05 PM
Edited Dec 4, 2013 at 3:05 PM
If forcing LIST solves the problems, you'll probably want to add the FtpListOption flag that pulls the date modified, parsing long listing formats provides inaccurate dates so adding that flag will tell System.Net.FtpClient to use MDTM, if it's available, to get accurate dates for files.It will attempt directories too but most servers don't support MDTM on directories.
Dec 4, 2013 at 3:09 PM

Hi,

Here is a log from WinSCP. I can barely keep up with you ( not a bad thing ).

I will try your suggestions in a couple of minutes.

Thank you VERY much !!!

Jim close

Dec 4, 2013 at 3:26 PM
We have liftoff !
The changes suggested worked. Sweet !!

Code change:
            string testfolder = "/" + conn.GetWorkingDirectory() + "/*";

            foreach (FtpListItem item in conn.GetListing(testfolder, FtpListOption.ForceList | FtpListOption.AllFiles))
Trace info:

220 Cornerstone MFT 9.10.1594 Ready.
USER dwgmgr_windsor
331 User name okay, need password.
PASS <omitted>
230-Welcome dwgmgr_windsor from 10.162.15.75. You are now logged in to the Alsto
m Power Inc FTP server.
230 User logged in, proceed.
FEAT
211-Extensions Supported
COMB
MLST type*;size*;modify*;create*;perm*;
SIZE
MDTM
MFMT
MFCT
EPRT
EPSV
XCRC
REST STREAM
DQTA
211 End
Text encoding: System.Text.ASCIIEncoding
SYST
215 UNIX Type: L8
PWD
257 "/srtFtpData/winvaultftp/dwgmgr_windsor/" is current directory.
PWD
257 "/srtFtpData/winvaultftp/dwgmgr_windsor/" is current directory.
TYPE I
200 Type set to I.
EPSV
229 Entering Extended Passive Mode (|||1765|)
LIST -a /srtFtpData/winvaultftp/dwgmgr_windsor/*
150 File status okay; about to open data connection.
drw-rw-rwx 1 dwgmgr_windsor dwgmgr_windsor 512 Dec 04 09:21 .
drw-rw-rwx 1 dwgmgr_windsor dwgmgr_windsor 512 Dec 04 09:21 ..
drw-rw-rwx 1 dwgmgr_windsor dwgmgr_windsor 512 Dec 04 09:21 me test
drw-rw-rwx 1 dwgmgr_windsor dwgmgr_windsor 512 Dec 04 09:21 testme
drw-rw---- 1 dwgmgr_windsor dwgmgr_windsor 512 Oct 11 14:45 HRSGDrawVau
lt
drw-rw---- 1 dwgmgr_windsor dwgmgr_windsor 512 Dec 02 08:28 UPBDrawVaul
t
drw-rw---- 1 dwgmgr_windsor dwgmgr_windsor 512 Dec 02 08:28 UPBImageVau
lt
226 Closing data connection. Transferred 551 bytes.
Disposing FtpSocketStream...
Failed to parse file listing: drw-rw-rwx 1 dwgmgr_windsor dwgmgr_windsor
512 Dec 04 09:21 .
Failed to parse file listing: drw-rw-rwx 1 dwgmgr_windsor dwgmgr_windsor
512 Dec 04 09:21 ..
/srtFtpData/winvaultftp/dwgmgr_windsor/*/me test
/srtFtpData/winvaultftp/dwgmgr_windsor/*/testme
/srtFtpData/winvaultftp/dwgmgr_windsor/*/HRSGDrawVault
/srtFtpData/winvaultftp/dwgmgr_windsor/*/UPBDrawVault
/srtFtpData/winvaultftp/dwgmgr_windsor/*/UPBImageVault
Disposing FtpClient object...
QUIT
221 Session Ended. Downloaded 0KB, Uploaded 0KB. Goodbye dwgmgr_windsor from 10.
162.15.75.
Disposing FtpSocketStream...


Once again, I could not be more impressed with the support.
Thank you !!
Coordinator
Dec 4, 2013 at 3:29 PM
No problem, note you'll probably want to take the asterisk out, I don't think it's needed and if you notice it messed up the paths:
/srtFtpData/winvaultftp/dwgmgr_windsor/*/me test 
/srtFtpData/winvaultftp/dwgmgr_windsor/*/testme 
/srtFtpData/winvaultftp/dwgmgr_windsor/*/HRSGDrawVault 
/srtFtpData/winvaultftp/dwgmgr_windsor/*/UPBDrawVault 
/srtFtpData/winvaultftp/dwgmgr_windsor/*/UPBImageVault 
Dec 4, 2013 at 3:33 PM
If I remove the asterick, I do not see the virtual folders.
This tactic will ONLY be used to get to the root virtual folder. Once inside, I will try without the asterick. Will let you know.


220 Cornerstone MFT 9.10.1594 Ready.
USER dwgmgr_windsor
331 User name okay, need password.
PASS <omitted>
230-Welcome dwgmgr_windsor from 10.162.15.75. You are now logged in to the Alsto
m Power Inc FTP server.
230 User logged in, proceed.
FEAT
211-Extensions Supported
COMB
MLST type*;size*;modify*;create*;perm*;
SIZE
MDTM
MFMT
MFCT
EPRT
EPSV
XCRC
REST STREAM
DQTA
211 End
Text encoding: System.Text.ASCIIEncoding
SYST
215 UNIX Type: L8
PWD
257 "/srtFtpData/winvaultftp/dwgmgr_windsor/" is current directory.
PWD
257 "/srtFtpData/winvaultftp/dwgmgr_windsor/" is current directory.
TYPE I
200 Type set to I.
EPSV
229 Entering Extended Passive Mode (|||1891|)
LIST -a /srtFtpData/winvaultftp/dwgmgr_windsor
150 File status okay; about to open data connection.
d--------- 1 dwgmgr_windsor dwgmgr_windsor 512 Dec 04 09:21 .
d--------- 1 dwgmgr_windsor dwgmgr_windsor 512 Dec 04 09:21 ..
d--------- 1 dwgmgr_windsor dwgmgr_windsor 512 Dec 04 09:21 me test
d--------- 1 dwgmgr_windsor dwgmgr_windsor 512 Dec 04 09:21 testme
226 Closing data connection. Transferred 300 bytes.
Disposing FtpSocketStream...
Failed to parse file listing: d--------- 1 dwgmgr_windsor dwgmgr_windsor
512 Dec 04 09:21 .
Failed to parse file listing: d--------- 1 dwgmgr_windsor dwgmgr_windsor
512 Dec 04 09:21 ..
/srtFtpData/winvaultftp/dwgmgr_windsor/me test
/srtFtpData/winvaultftp/dwgmgr_windsor/testme
Disposing FtpClient object...
QUIT
221 Session Ended. Downloaded 0KB, Uploaded 0KB. Goodbye dwgmgr_windsor from 10.
162.15.75.
Disposing FtpSocketStream...
Coordinator
Dec 4, 2013 at 3:36 PM
OK, well this is a bug I need to address, the asterisk should be stripped from the end of the path by System.Net.FtpClient, it's not a problem with the server. For what it's worth, if that worked the original approach you took may have worked with an asterisk, i.e., without the ForceList option, which would use MLSD which is much better than LIST. May want to give it a try just to see.
Coordinator
Dec 4, 2013 at 3:37 PM
Also, the AllFiles flag just tells System.Net.FtpClient to use LIST -a as opposed to LIST. Some servers support this, some don't, that's the reason it's an optional flag.
Dec 4, 2013 at 3:42 PM
I tried the latest suggestion with partial success.
The virtual folder show, but the local folders do not.

Code change:
            string testfolder = "/" + conn.GetWorkingDirectory() + "/*";
            foreach (FtpListItem item in conn.GetListing(testfolder, FtpListOption.AllFiles))
Trace log:

220 Cornerstone MFT 9.10.1594 Ready.
USER dwgmgr_windsor
331 User name okay, need password.
PASS <omitted>
230-Welcome dwgmgr_windsor from 10.162.15.75. You are now logged in to the Alsto
m Power Inc FTP server.
230 User logged in, proceed.
FEAT
211-Extensions Supported
COMB
MLST type*;size*;modify*;create*;perm*;
SIZE
MDTM
MFMT
MFCT
EPRT
EPSV
XCRC
REST STREAM
DQTA
211 End
Text encoding: System.Text.ASCIIEncoding
SYST
215 UNIX Type: L8
PWD
257 "/srtFtpData/winvaultftp/dwgmgr_windsor/" is current directory.
PWD
257 "/srtFtpData/winvaultftp/dwgmgr_windsor/" is current directory.
TYPE I
200 Type set to I.
EPSV
229 Entering Extended Passive Mode (|||2062|)
MLSD /srtFtpData/winvaultftp/dwgmgr_windsor/*
150 File status okay; about to open data connection.
type=dir;size=512;modify=20131011194502;create=20070808110824;perm=cdeflmp; HRSG
DrawVault
type=dir;size=512;modify=20131202132858;create=20100301024029;perm=cdeflmp; UPBD
rawVault
type=dir;size=512;modify=20131202132858;create=20100128201847;perm=cdeflmp; UPBI
mageVault
226 Closing data connection. Transferred 272 bytes.
Disposing FtpSocketStream...
/srtFtpData/winvaultftp/dwgmgr_windsor/*/HRSGDrawVault
/srtFtpData/winvaultftp/dwgmgr_windsor/*/UPBDrawVault
/srtFtpData/winvaultftp/dwgmgr_windsor/*/UPBImageVault
Disposing FtpClient object...
QUIT
221 Session Ended. Downloaded 0KB, Uploaded 0KB. Goodbye dwgmgr_windsor from 10.
162.15.75.
Disposing FtpSocketStream...
Coordinator
Dec 4, 2013 at 4:45 PM
I just pushed up a new revision that cleans out the wild card/globs from the path when creating the FtpListItem objects.
Coordinator
Dec 4, 2013 at 4:46 PM
jtclose wrote:
I tried the latest suggestion with partial success.
The virtual folder show, but the local folders do not.

Code change:
            string testfolder = "/" + conn.GetWorkingDirectory() + "/*";
            foreach (FtpListItem item in conn.GetListing(testfolder, FtpListOption.AllFiles))
Alright, then I would just stick with LIST and the FtpListOption.Modify flag.
Dec 4, 2013 at 5:57 PM
Edited Dec 4, 2013 at 11:16 PM
Sorry for the lack of etiquette. My bad.

I now can enumerate the entry folder and return all folders under the initial user folder.

The next issue is to navigate to one of the Virtual folders, for that is where the money is.

I can not SetWorkingDirectory to the Virtual folder, at least with the paths I have created.
I have to remember that what is returned is not what I need to pass. Suggestion ?

Offending value:

targetFolder = "/srtFtpData/winvaultftp/dwgmgr_windsor/UPBDrawVault//*"
Look for FAILS HERE id the code.


Here is the Code:
    public static void GetListing()
    {
        using (FtpClient conn = new FtpClient()) {
            conn.Host = "ftpsite";
            conn.Credentials = new NetworkCredential("ftpuser", "ftppass");
            conn.Credentials.Domain = "domx";
            conn.SocketKeepAlive = true;
            string remoteSystemType = conn.SystemType;               
            conn.DataConnectionType = FtpDataConnectionType.AutoPassive;
            string targetFolder = null;
            //      tried hack with no luck    string testfolderB = @"/srtFtpData/winvaultftp/dwgmgr_windsor/UPBDrawVault";

            string testfolder = "/" + conn.GetWorkingDirectory() + "/*";
            //      returns     testfolder = @""//srtFtpData/winvaultftp/dwgmgr_windsor//*"";

            foreach (FtpListItem item in conn.GetListing(testfolder, FtpListOption.ForceList | FtpListOption.AllFiles))
            {

                switch (item.Type) {
                    case FtpFileSystemObjectType.Directory:
                        Console.WriteLine(item.FullName);

                        if (item.FullName.ToString().Contains("UPBDrawVault"))
                        {
                            targetFolder = item.FullName.ToString().Replace("*/","") + @"//*";
                        }
                        else
                            targetFolder = null;


                        break;
                    case FtpFileSystemObjectType.File:
                        Console.WriteLine(item.FullName);
                        break;
                    case FtpFileSystemObjectType.Link:
                        // derefernece symbolic links
                        if (item.LinkTarget != null) {
                            // see the DereferenceLink() example
                            // for more details about resolving links.
                            item.LinkObject = conn.DereferenceLink(item);

                            if (item.LinkObject != null) {
                                Console.WriteLine(item.FullName);
                                // switch (item.LinkObject.Type)...
                            }
                        }
                        break;
                }

                if (targetFolder != null)
                {
                    conn.SetWorkingDirectory(targetFolder)  // FAILS HERE 
                    foreach (FtpListItem itemX in conn.GetListing(targetFolder,FtpListOption.ForceList | FtpListOption.AllFiles))
                    {
                        switch (itemX.Type)
                        {
                            case FtpFileSystemObjectType.Directory:
                                Console.WriteLine(itemX.FullName);
                                break;
                            case FtpFileSystemObjectType.File:
                                Console.WriteLine(itemX.FullName);
                                break;
                            case FtpFileSystemObjectType.Link:
                                // derefernece symbolic links
                                if (itemX.LinkTarget != null)
                                {
                                    // see the DereferenceLink() example
                                    // for more details about resolving links.
                                    itemX.LinkObject = conn.DereferenceLink(item);

                                    if (itemX.LinkObject != null)
                                    {
                                        Console.WriteLine(itemX.FullName);
                                        // switch (item.LinkObject.Type)...
                                    }
                                }
                                break;
                        }
                    }


                }
            }

        }
    }

Here is the Exception:

System.Net.FtpClient.FtpCommandException was unhandled
Message=File name not allowed, or file type banned.
Source=System.Net.FtpClient
CompletionCode=553
StackTrace:
   at System.Net.FtpClient.FtpClient.SetWorkingDirectory(String path)
   at testFTP.Program.GetListing() in D:\jtcc#\testFTP\testFTP\Program.cs:line 90
   at testFTP.Program.Main(String[] args) in D:\jtcc#\testFTP\testFTP\Program.cs:line 19
   at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
   at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
   at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
   at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ThreadHelper.ThreadStart()
InnerException:

Here is the Trace:

220 Cornerstone MFT 9.10.1594 Ready.
USER dwgmgr_windsor
331 User name okay, need password.
PASS <omitted>
230-Welcome dwgmgr_windsor from 10.162.15.75. You are now logged in to the Alsto
m Power Inc FTP server.
230 User logged in, proceed.
FEAT
211-Extensions Supported
COMB
MLST type*;size*;modify*;create*;perm*;
SIZE
MDTM
MFMT
MFCT
EPRT
EPSV
XCRC
REST STREAM
DQTA
211 End
Text encoding: System.Text.ASCIIEncoding
SYST
215 UNIX Type: L8
PWD
257 "/srtFtpData/winvaultftp/dwgmgr_windsor/" is current directory.
PWD
257 "/srtFtpData/winvaultftp/dwgmgr_windsor/" is current directory.
TYPE I
200 Type set to I.
EPSV
229 Entering Extended Passive Mode (|||4436|)
LIST -a /srtFtpData/winvaultftp/dwgmgr_windsor/*
150 File status okay; about to open data connection.
drw-rw-rwx 1 dwgmgr_windsor dwgmgr_windsor 512 Dec 04 09:21 .
drw-rw-rwx 1 dwgmgr_windsor dwgmgr_windsor 512 Dec 04 09:21 ..
drw-rw-rwx 1 dwgmgr_windsor dwgmgr_windsor 512 Dec 04 09:21 me test
drw-rw-rwx 1 dwgmgr_windsor dwgmgr_windsor 512 Dec 04 09:21 testme
drw-rw---- 1 dwgmgr_windsor dwgmgr_windsor 512 Oct 11 14:45 HRSGDrawVau
lt
drw-rw---- 1 dwgmgr_windsor dwgmgr_windsor 512 Dec 02 08:28 UPBDrawVaul
t
drw-rw---- 1 dwgmgr_windsor dwgmgr_windsor 512 Dec 02 08:28 UPBImageVau
lt
226 Closing data connection. Transferred 551 bytes.
Disposing FtpSocketStream...
Failed to parse file listing: drw-rw-rwx 1 dwgmgr_windsor dwgmgr_windsor
512 Dec 04 09:21 .
Failed to parse file listing: drw-rw-rwx 1 dwgmgr_windsor dwgmgr_windsor
512 Dec 04 09:21 ..
/srtFtpData/winvaultftp/dwgmgr_windsor/*/me test
/srtFtpData/winvaultftp/dwgmgr_windsor/*/testme
/srtFtpData/winvaultftp/dwgmgr_windsor/*/HRSGDrawVault
/srtFtpData/winvaultftp/dwgmgr_windsor/*/UPBDrawVault
CWD /srtFtpData/winvaultftp/dwgmgr_windsor/UPBDrawVault/*
553 File name not allowed, or file type banned.

Thanks again !
Coordinator
Dec 4, 2013 at 5:59 PM
Download the latest source revision that pushed up a little while ago which should clear up the problem of the * in the path names.
Dec 4, 2013 at 7:09 PM
Rookie at the wheel ... I have been referencing the DLL.
I am to edit my copy of the source, remake the DLL ?
Coordinator
Dec 4, 2013 at 7:14 PM
Go to the source code section and click the Download link at the top right.

Option 1.:

Extract the ZIP file, Open FtpClient.sln, change Debug to Release in the toolbar if necessary, and build the solution. Copy the System.Net.FtpClient\bin\Release\System.Net.FtpClient.dll file over to your project.

Option 2.:

Extract the zip file and move the System.Net.FtpClient sub folder over to your Solution folder for the project you're working on. In your current project, remove the references to System.Net.FtpClient.dll. Right click on the solution and choose Add Project, browse to the System.Net.FtpClient\System.Net.FtpClient.csproj file. Once that's done, right click on the references of your current project and choose Add Reference -> Project -> System.Net.FtpClient.
Dec 4, 2013 at 7:29 PM
Thanks coach. I am on it.
Dec 4, 2013 at 7:51 PM
Edited Dec 4, 2013 at 11:14 PM
Game, Set, Match ! Thank you VERY much !!

I do have to use a different string for the SetWorkingDirectory versus the path used in the FtpListItem

targetFolder = item.FullName.ToString();
targetFtpItemFolder = item.FullName.ToString().Replace("/", "") + @"//";
        using (FtpClient conn = new FtpClient()) {
            conn.Host = "ftpsite";
            conn.Credentials = new NetworkCredential("ftpuser", "ftppass");
            conn.Credentials.Domain = "domx";
            conn.SocketKeepAlive = true;
            string remoteSystemType = conn.SystemType;               
            conn.DataConnectionType = FtpDataConnectionType.AutoPassive;
            string targetFolder = null;
            string targetFtpItemFolder = null;

            string testfolder = "/" + conn.GetWorkingDirectory() + "/*";

            foreach (FtpListItem item in conn.GetListing(testfolder, FtpListOption.ForceList | FtpListOption.AllFiles))
            {

                switch (item.Type) {
                    case FtpFileSystemObjectType.Directory:
                        Console.WriteLine(item.FullName);

                        if (item.FullName.ToString().Contains("UPBDrawVault"))
                        {
                            targetFolder = item.FullName.ToString();
                            targetFtpItemFolder = item.FullName.ToString().Replace("*/", "") + @"//*";
                        }
                        else
                            targetFolder = null;


                        break;
                    case FtpFileSystemObjectType.File:
                        Console.WriteLine(item.FullName);
                        break;
                    case FtpFileSystemObjectType.Link:
                        // derefernece symbolic links
                        if (item.LinkTarget != null) {
                            // see the DereferenceLink() example
                            // for more details about resolving links.
                            item.LinkObject = conn.DereferenceLink(item);

                            if (item.LinkObject != null) {
                                Console.WriteLine(item.FullName);
                                // switch (item.LinkObject.Type)...
                            }
                        }
                        break;
                }

                if (targetFolder != null)
                {
                    conn.SetWorkingDirectory(targetFolder);
                    foreach (FtpListItem itemX in conn.GetListing(targetFtpItemFolder, FtpListOption.ForceList | FtpListOption.AllFiles))
                    {
                        switch (itemX.Type)
                        {
                            case FtpFileSystemObjectType.Directory:
                                Console.WriteLine(itemX.FullName);
                                break;
                            case FtpFileSystemObjectType.File:
                                Console.WriteLine(itemX.FullName);
                                break;
                            case FtpFileSystemObjectType.Link:
                                // derefernece symbolic links
                                if (itemX.LinkTarget != null)
                                {
                                    // see the DereferenceLink() example
                                    // for more details about resolving links.
                                    itemX.LinkObject = conn.DereferenceLink(item);

                                    if (itemX.LinkObject != null)
                                    {
                                        Console.WriteLine(itemX.FullName);
                                        // switch (item.LinkObject.Type)...
                                    }
                                }
                                break;
                        }
                    }


                }
            }

        }
    }
Coordinator
Dec 4, 2013 at 7:53 PM
That's odd, I tested with wildcards and the FullName property had the asterisks removed, as expected.
Dec 4, 2013 at 8:01 PM
I have the Trace. Is it a bit long. 1367 lines. Email it or post it ? What can I do to help ?
Dec 4, 2013 at 9:50 PM

Here is the Trace file.

Thank you very much !

Jim Close

Dec 4, 2013 at 11:24 PM
I have gone back and scrubbed the code section to remove passwords
In the above examples, in order to make the correct associations in the log files

ftpsite = winvaultftp
ftpuser = dwgmgr_windsor
Coordinator
Dec 5, 2013 at 2:01 PM
I've pushed up a new revision that improves the removal of the globbing pattern from the last segment of the path passed to GetListing(). I've tested several scenarios and I know it works correctly. Please get the latest revision and make sure you reference the new DLL and not an older one.
Dec 5, 2013 at 3:09 PM
I have download the new code, made the DLL and ran the test successfully.
I still have the code to create separate a path strings for ...
targetFolder = item.FullName.ToString();
SetWorkingDirectory(targetFolder)

targetFtpItemFolder = item.FullName.ToString().Replace("*/", "") + @"//*";
GetListing(targerFtpItemFolder
Is that expected ?
Dec 5, 2013 at 3:15 PM
Using the same path string for SetWorkingDirectory() and GetList() does not work.
Coordinator
Dec 5, 2013 at 3:24 PM
Can you post the transaction log here of what's not working? And are you sure you're running the latest source? I need to see what you're executing and how System.Net.FtpClient is parsing it.
Coordinator
Dec 5, 2013 at 3:26 PM
Specifically we want to see the transaction log and the item.FullName property which should contain the full path to the object minus the wild cards.
Dec 5, 2013 at 3:44 PM
This is the download I got and remade the DLL.
System.Net.FtpClient version 1.0.5087.17518 Correct ?

Trace Log:
Example: with different path strings for SetWorkingDirectory and GetListing
                            targetFolder = item.FullName.ToString();
                            targetFtpItemFolder = item.FullName.ToString().Replace("*/", "") + @"//*";


220 Cornerstone MFT 9.10.1594 Ready.
USER dwgmgr_windsor
331 User name okay, need password.
PASS <omitted>
230-Welcome dwgmgr_windsor from 10.162.15.75. You are now logged in to the Alstom Power Inc FTP server.
230 User logged in, proceed.
FEAT
211-Extensions Supported
COMB
MLST type*;size*;modify*;create*;perm*;
SIZE
MDTM
MFMT
MFCT
EPRT
EPSV
XCRC
REST STREAM
DQTA
211 End
Text encoding: System.Text.ASCIIEncoding
SYST
215 UNIX Type: L8
PWD
257 "/srtFtpData/winvaultftp/dwgmgr_windsor/" is current directory.
PWD
257 "/srtFtpData/winvaultftp/dwgmgr_windsor/" is current directory.
TYPE I
200 Type set to I.
EPSV
229 Entering Extended Passive Mode (|||3264|)
LIST -a /srtFtpData/winvaultftp/dwgmgr_windsor/*
150 File status okay; about to open data connection.
drw-rw-rwx 1 dwgmgr_windsor dwgmgr_windsor 512 Dec 04 09:21 .
drw-rw-rwx 1 dwgmgr_windsor dwgmgr_windsor 512 Dec 04 09:21 ..
drw-rw-rwx 1 dwgmgr_windsor dwgmgr_windsor 512 Dec 04 09:21 me test
drw-rw-rwx 1 dwgmgr_windsor dwgmgr_windsor 512 Dec 04 09:21 testme
drw-rw---- 1 dwgmgr_windsor dwgmgr_windsor 512 Oct 11 14:45 HRSGDrawVault
drw-rw---- 1 dwgmgr_windsor dwgmgr_windsor 512 Dec 05 08:25 UPBDrawVault
drw-rw---- 1 dwgmgr_windsor dwgmgr_windsor 512 Dec 05 08:25 UPBImageVault
226 Closing data connection. Transferred 551 bytes.
Disposing FtpSocketStream...
Failed to parse file listing: drw-rw-rwx 1 dwgmgr_windsor dwgmgr_windsor 512 Dec 04 09:21 .
Failed to parse file listing: drw-rw-rwx 1 dwgmgr_windsor dwgmgr_windsor 512 Dec 04 09:21 ..
me test
testme
HRSGDrawVault
UPBDrawVault
UPBImageVault
CWD /srtFtpData/winvaultftp/dwgmgr_windsor/UPBDrawVault
250 Directory changed to "/srtFtpData/winvaultftp/dwgmgr_windsor/UPBDrawVault/"
PWD
257 "/srtFtpData/winvaultftp/dwgmgr_windsor/UPBDrawVault/" is current directory.
TYPE I
200 Type set to I.
EPSV
229 Entering Extended Passive Mode (|||3268|)
LIST -a /srtFtpData/winvaultftp/dwgmgr_windsor/UPBDrawVault/*
150 File status okay; about to open data connection.
drw-rw-rwx 1 dwgmgr_windsor dwgmgr_windsor 512 Dec 05 08:25 .
drw-rw-rwx 1 dwgmgr_windsor dwgmgr_windsor 512 Aug 20 12:33 00100
drw-rw-rwx 1 dwgmgr_windsor dwgmgr_windsor 512 Apr 10 2013 00101
drw-rw-rwx 1 dwgmgr_windsor dwgmgr_windsor 512 Oct 01 14:16 00102
drw-rw-rwx 1 dwgmgr_windsor dwgmgr_windsor 512 Jul 17 2012 00103
drw-rw-rwx 1 dwgmgr_windsor dwgmgr_windsor 512 Aug 24 2012 00104
drw-rw-rwx 1 dwgmgr_windsor dwgmgr_windsor 512 Oct 03 16:20 00105
drw-rw-rwx 1 dwgmgr_windsor dwgmgr_windsor 512 Apr 11 2011 00106
drw-rw-rwx 1 dwgmgr_windsor dwgmgr_windsor 512 Dec 05 08:06 00108
drw-rw-rwx 1 dwgmgr_windsor dwgmgr_windsor 512 Nov 18 11:49 00109
drw-rw-rwx 1 dwgmgr_windsor dwgmgr_windsor 512 Nov 22 15:16 00110
drw-rw-rwx 1 dwgmgr_windsor dwgmgr_windsor 512 Jan 09 2013 00192
drw-rw-rwx 1 dwgmgr_windsor dwgmgr_windsor 512 Feb 28 2010 00195
drw-rw-rwx 1 dwgmgr_windsor dwgmgr_windsor 512 May 29 2013 00196
drw-rw-rwx 1 dwgmgr_windsor dwgmgr_windsor 512 Feb 27 2013 00199
drw-rw-rwx 1 dwgmgr_windsor dwgmgr_windsor 512 Dec 30 2010 00201

... Hacked off Log to fit ....

Trace Log: Example using same path string for both functions
                            targetFolder = item.FullName.ToString();
                            targetFtpItemFolder = targetFolder;
Log file is empty. Does the CWD , but no listing of the child Virtual folder

Trace Log: Example using same path string for both functions
                            targetFtpItemFolder = item.FullName.ToString().Replace("*/", "") + @"//*";
                            targetFolder = targetFtpItemFolder;
Exception tossed on conn.SetWorkingDirectory(targetFolder);
Log file is empty: Dies trying to CWD
Coordinator
Dec 5, 2013 at 3:51 PM
It looks to me that you're appending asterisks to the end of your targetFolder you're attempting to change directory to. This is not acceptable, SetWorkingDirectory() expects a valid path name and a valid path doesn't include an asterisk. GetListing() will take a path with an asterisk, no problem, and it will remove the asterisk when it reconstructs the path for the FullName property of the FtpListItem. I hope this makes sense. I believe the problem is here:
targetFtpItemFolder = item.FullName.ToString().Replace("*/", "") + @"//*";
targetFolder = targetFtpItemFolder;
conn.SetWorkingDirectory(targetFolder); 
This would be more acceptable:
conn.GetListing(item.FullName + "/*");
Dec 5, 2013 at 3:52 PM
The returned value for targetFolder = item.FullName.ToString();
  is "/srtFtpData/winvaultftp/dwgmgr_windsor/UPBDrawVault"
Looks like I can remove the replacement of */ but still need the @// appended to the end
Coordinator
Dec 5, 2013 at 4:04 PM
OK, well the bottom line is the same rules for local file systems apply here. You wouldn't:
cd /srtFtpData/winvaultftp/dwgmgr_windsor/UPBDrawVault*
to change the working directory in a command prompt on your computer. You would:
cd /srtFtpData/winvaultftp/dwgmgr_windsor/UPBDrawVault
However, if you wanted to list objects that matched a certain criteria on the command prompt you would indeed use an asterisk, for example:
ls /srtFtpData/winvaultftp/dwgmgr_windsor/UPBDrawVault/*.txt
Coordinator
Dec 5, 2013 at 4:09 PM
I've invested all of the time I can afford into this problem. I believe it is solved with the latest revisions, as it looks to me that the problems you're having now are due to a lack of understanding of globbing/wildcards. Once you get your code adjusted accordingly I think that you will be able to move forward. I hope that I've been clear in explaining where using a asterisk, aka glob or wild card, would be appropriate. Just remember that the same rules that apply to the local file system apply here: Asterisks are on valid with matching a group of objects and the only place in System.Net.FtpClient where that would be applicable is with the GetListing() method. The actual pattern matching is done by the server, not by System.Net.FtpClient. It sends the literal string "LIST /srtFtpData/winvaultftp/dwgmgr_windsor/UPBDrawVault*" to the server and the server processes it and sends the results.
Dec 5, 2013 at 4:16 PM
I have a workable solution, Thank you !
You obvisiously do not work in a large corporation otherwise this would have been a month long thread !

Your lastest suggestion does work, so I will use it.
Once again, thank you.

Now for the most famous words in IT land ...
"Close the Ticket" !
Coordinator
Dec 5, 2013 at 4:21 PM
jtclose wrote:
You obvisiously do not work in a large corporation otherwise this would have been a month long thread !
Nope, this is just a hobby for me at this point, it's long since exceeded my use case. While I do development professionally my primary job function is systems administration and the vast majority of the code I write is to make my life easier, very few projects that go on to end users in our company. If you stick with programming long enough you'll probably come back and look at this code and be able to pick up on that easily, as I'm sure it's not the best around but it does work for myself and most others it seems. :)