I am using AT commands on gprs to do ftp . We have everything working until we send RETR a.exe .
The file data is also sent on the port. But it contains the response headers like RECEIVE:1,1400 ,may be from the modem of the device and ftp server responses also like 150 connection accepted etc. How do we write this file so that we will have a uncorrupted a.exe which will run on the client device. Please advise. We are using C#. Should we remove the headers. How do we do it . Get a good exe file ?
And even to remove unwanted characters from the ftp data, we need to remove single single characters from the string and its taking so much time to remove it (and all other string functions are not working here like replace or remove).
And if we are using sockets, its giving problem in opening the data connection through the socket.
(Device used --- winCE )
Thanks
Here is the code i am using
void Readfully()
{
byte[] chunk = new byte[4096];
int count;
int flg = 0;
string temp_ReceveivedFile = "";
string result = "";
StreamWriter writer = new StreamWriter(File.Open("a.exe", FileMode.Create));
back:
try
{
Array.Clear(chunk, 0, chunk.Length);
while (true)
{
count = port.Read(chunk, 0, chunk.Length);
temp_ReceveivedFile = System.Text.Encoding.ASCII.GetString(chunk, 0, count);
writer.Write(temp_ReceveivedFile);
if (temp_ReceveivedFile.Contains("Transfer OK"))
{
break;
}
else if (temp_ReceveivedFile.Contains(" 425 Can't open data connection."))
{
System.Windows.Forms.MessageBox.Show(" 425 Can't open data connection.");
break;
}
flg = 0;
Array.Clear(chunk, 0, count);
}
}
catch (Exception ex)
{
flg++;
if (flg < 3)
goto back;
}
writer.Close();
* /
StreamReader sr = new StreamReader("a.exe");
String RWBuff;
StreamWriter wr = new StreamWriter(File.Open("a_new.exe", FileMode.Create));
while (true)
{
RWBuff = sr.ReadLine();
if (RWBuff.Contains("+RECEIVE,1,1400:"))
{
break;
}
}
while(true)
{
try
{
RWBuff = sr.ReadLine();
if (!RWBuff.Contains("Transfer OK"))
{
if (!RWBuff.Contains("+RECEIVE,1,1400:") && RWBuff!=null)
{
result = RWBuff + "\n";
wr.Write(result);
}
}
else
break;
}
catch(Exception Eww)
{}
}
sr.Close();
wr.Close();
}
}
}
Here port.read is not reading all bytes of data