I'm with something new, I'm blocked and I don't know how to do the truth.
I am making a program that downloads by FTP to do a series of steps, the first thing is to download.
Here I have the code that makes the download which works perfect:
public static void DescargarFichero(string ficFTP, string user, string pass, string dirLocal, Boolean UsePassive, Boolean UseBinary)
{
FtpWebRequest dirFtp = ((FtpWebRequest)FtpWebRequest.Create(ficFTP));
dirFtp.KeepAlive = true;
dirFtp.UsePassive = UsePassive;
dirFtp.UseBinary = UseBinary;
// Los datos del usuario (credenciales)
NetworkCredential cr = new NetworkCredential(user, pass);
dirFtp.Credentials = cr;
FtpWebResponse response = (FtpWebResponse)dirFtp.GetResponse();
Stream responseStream = response.GetResponseStream();
StreamReader reader = new StreamReader(responseStream);
using (FileStream writer = new FileStream(dirLocal, FileMode.Create))
{
long length = response.ContentLength;
int bufferSize = 2048;
int readCount;
byte[] buffer = new byte[2048];
readCount = responseStream.Read(buffer, 0, bufferSize);
while (readCount > 0)
{
writer.Write(buffer, 0, readCount);
readCount = responseStream.Read(buffer, 0, bufferSize);
Console.WriteLine("Descargando...");
}
}
reader.Close();
response.Close();
}
I am doing tests in a console application, but the future is to use windows form and that it looks good, my blocking is this: How can I show this to happen:
while (readCount > 0)
{
writer.Write(buffer, 0, readCount);
readCount = responseStream.Read(buffer, 0, bufferSize);
Console.WriteLine("Descargando...");
}
I can find out that this function is executing and that it is "downloading" I am looking for that every time that cycle is iterating I can return a value without having to break the cycle. My idea is to be able to say If Value is = X then "downloading"
Newbie question? Yes, I am blocked and I don't know how to get out of the "rat race". I hope you can help me.