Highlighted
Super Contributor.
Super Contributor.
527 views

More about ftp.

Jump to solution
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
 
0 Likes
1 Solution

Accepted Solutions
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: More about ftp.

Jump to solution

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()

View solution in original post

0 Likes
1 Reply
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: More about ftp.

Jump to solution

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()

View solution in original post

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.