More about ftp.

Now I need to download a file that is in an FTP folder, I found the routine in C # but I do not master the language.

FtpWebRequest request = (FtpWebRequest)WebRequest.Create("servidor.com.br/.../logo.png"); request.Method = WebRequestMethods.Ftp.DownloadFile; request.Credentials = new NetworkCredential("usuario", "senha"); request.UsePassive = true; request.UseBinary = true; request.KeepAlive = true; FtpWebResponse response = (FtpWebResponse)request.GetResponse(); Stream responseStream = response.GetResponseStream(); byte[] buffer = new byte[2048]; FileStream newFile = new FileStream("c:\\wwwroot\\exemplos\\logo.png", FileMode.Create); int readCount = responseStream.Read(buffer, 0, buffer.Length); while (readCount > 0) { //Escrever o arquivo newFile.Write(buffer, 0, readCount); readCount = responseStream.Read(buffer, 0, buffer.Length); } newFile.Close(); responseStream.Close(); response.Close();

thank you
 
  • Verified Answer

    Something like this:

     

               declare request as type FtpWebRequest = type WebRequest::Create("servidor.com.br/.../logo.png") as type FtpWebRequest
               set request::Method = type WebRequestMethods Ftp::DownloadFile
               set request::Credentials = new NetworkCredential("usuario", "senha")
               set request::UsePassive = true
               set request::UseBinary = true
               set request::KeepAlive = true
    
               declare response as type FtpWebResponse = request::GetResponse as type FtpWebResponse
               declare responseStream as type Stream = response::GetResponseStream
    
               declare buffer as type Byte occurs 2048
               declare newFile as type FileStream = new FileStream("c:\\wwwroot\\exemplos\\logo.png", type FileMode::Create)
               declare readCount as binary-long = responseStream::Read(buffer, 0, buffer::Length)
               perform until readCount <= 0
              	  *>//Escrever o arquivo
    	          invoke newFile::Write(buffer, 0, readCount)
    	          set readCount = responseStream::Read(buffer, 0, buffer::Length)
               end-perform
               invoke newFile::Close
               invoke responseStream::Close
               invoke response::Close()