Using FtpWebRequest
to list the contents of a directory; however, it's not showing the hidden files.
How do I get it to show the hidden files?
FtpWebRequest request = (FtpWebRequest)WebRequest.Create(ftp_root + path);
request.Method = WebRequestMethods.Ftp.ListDirectory;
FileZilla lists the hidden files correctly so I know the FTP server is returning that data to it. I just need to replicate that with FtpWebRequest
. Or use a different library for it.
Some FTP servers fail to include hidden files to responses to
LIST
andNLST
commands (which are behind theListDirectoryDetails
andListDirectory
).One solution is to use
MLSD
command, to which FTP servers do return hidden files. TheMLSD
command is anyway the only right way to talk to an FTP server, as its response format is standardized (what is not the case withLIST
).But .NET framework/
FtpWebRequest
does not support theMLSD
command.For that you would have to use a different 3rd party FTP library.
For example with WinSCP .NET assembly you can use:
See documentation for
Session.ListDirectory
method.WinSCP will use
MLSD
, if the server supports it. If not, it will try to use-a
trick (described below).(I'm the author of WinSCP)
If you are stuck with
FtpWebRequest
, you can try to use-a
switch with theLIST
/NLST
command. While that's not any standard switch (there are no switches in FTP), many FTP servers do recognize it. And it makes them return hidden files.To trick
FtpWebRequest
to add the-a
switch toLIST
/NLST
command, add it to the URL:The
FtpWebRequest
which is provided by Microsoft does not perform all the operations neccessary for listing FTP, FTPS or SFTP site's directories.A good solution would be to use some other dll's like WinScp, Ftp.dll which can provide you with some efficient and extra functionalities.