Search code examples
c#.netftpreadfilehidden-files

C# Read file in ftp when this file start with dot "." (hidden Files)


I need read file in ftp, but this file start with a "." (hidden Files), for exemple .teste.txt.

I tried read this file using this code:

 FtpWebRequest reqFTP;
 reqFTP = (FtpWebRequest)WebRequest.Create("ftp://" + strFTP + ":" + strPorta + strDiretorio);
 reqFTP.Method = WebRequestMethods.Ftp.ListDirectory;
 reqFTP.Credentials = new NetworkCredential(strUser, strPass);

 response = (FtpWebResponse)reqFTP.GetResponse();

 reader = new StreamReader(response.GetResponseStream());
 string line = reader.ReadLine();

Solution

  • in this case I put " -al" in the end ftp url, using this code:

     var reqFTP = (FtpWebRequest)WebRequest.Create("ftp://" + strFTP + ":" + strPorta + strDiretorio + " -al");
    
    reqFTP.Method = WebRequestMethods.Ftp.ListDirectory;
    reqFTP.Credentials = new NetworkCredential(strUser, strPass);
    
    response = (FtpWebResponse)reqFTP.GetResponse();
    
    reader = new StreamReader(response.GetResponseStream());
    string line = reader.ReadLine();