Is it possible to simulate a FTP server in C #? [closed]

1

I need to run automated integration tests in an application whose functionalities have external dependencies such as FTP. I would like to know if it is possible to simulate an FTP as it is possible to simulate a database with Moq, for example.

Until then, in my searches I only found NuGet frameworks and packages that create FTP servers, but it is not my goal at the moment. I would like to resort to this only if it is not possible to simulate the tests.

For now, I've created a class that communicates with an existing FTP server.

    public class FTPComunicacao
    {
private void DownloadArquivo(string ftpDiretorioPath, string username, string senha, string destinoLocalArquivoPath) { int bytesRead = 0; byte[] buffer = new byte[2048]; FtpWebRequest ftp = (FtpWebRequest)WebRequest.Create(new Uri(ftpDiretorioPath)); ftp.Method = WebRequestMethods.Ftp.DownloadFile; Stream reader = ftp.GetResponse().GetResponseStream(); FileStream fileStream = new FileStream(destinoLocalArquivoPath, FileMode.Create); while (true) { bytesRead = reader.Read(buffer, 0, buffer.Length); if(bytesRead == 0) { break; } fileStream.Write(buffer, 0, bytesRead); } fileStream.Close(); } private FtpWebRequest CriaRequisicaoFtp(string ftpDiretorioPath, string username, string senha, bool keepAlive = false) { FtpWebRequest ftp = (FtpWebRequest)WebRequest.Create(new Uri(ftpDiretorioPath)); //Setar o proxy como nulo porque se não, o proxy usado vai receber uma resposta html do monitoramento firewall ftp.Proxy = null; ftp.UsePassive = true; ftp.UseBinary = true; ftp.KeepAlive = keepAlive; ftp.Credentials = new NetworkCredential(username, senha); return ftp; } }

    
asked by anonymous 16.10.2018 / 19:05

0 answers