I'd like to check the following process relating to the uploading of data by FTP, after the data is read from a database.
I have a stored procedure that returns data in the following pipe delimited format in a single column. It typically returns around 300 rows, each row has about 300 bytes.
1234|||||PROPERTY|||MARKET INDEX|||||ADDRESS|||||1||||GBP|||||||20110930||||||||C|OFFICE|F||
The application then submits that data by FTP, typically <100k overall.
Here's the mechanism used, restricted to .NET 3.5.
// database method returns dataset/datareader, converted and passed to method as
// IEnumerable<string> data
string ftpServerIP = "5.4.3.2:21";
string targetFileName = "mann.txt";
string username = "manfred";
string password = "*******";
Uri uri = new Uri(String.Format("ftp://{0}/{1}", ftpServerIP, targetFileName));
FtpWebRequest reqFTP = (FtpWebRequest)FtpWebRequest.Create(uri);
reqFTP.Credentials = new NetworkCredential(username, password);
reqFTP.Method = WebRequestMethods.Ftp.UploadFile;
reqFTP.KeepAlive = false;
reqFTP.UsePassive = false;
MemoryStream stIn = new MemoryStream();
using (StreamWriter sw = new StreamWriter(stIn))
{
foreach (string item in data)
{
sw.WriteLine(item);
}
sw.Flush();
using (Stream stOut = reqFTP.GetRequestStream())
{
stOut.Write(stIn.GetBuffer(), 0, (int)stIn.Length);
}
}
FtpWebResponse response = (FtpWebResponse)reqFTP.GetResponse();
response.Close();
I'd like to check whether the stream and ftp processing looks ok, or whether there are other stream types to consider (BufferedStream?), or closure/disposal steps, etc...
}(as StyleCop would suggest). I would also build out a URI withString.Format. \$\endgroup\$