- For individual users
- Instant access to solutions
- Ask your tech questions
- Start your 30-day Free Trial
Main Topics
Browse All TopicsI've got the following method that is throwing an error...
public static void Download(String strFileName)
{
FtpWebRequest ftp = null;
Stream ftpStream = null;
FileStream fs = null;
FtpWebResponse response = null;
try
{
fs = new FileStream(strPath + strFileName, FileMode.Create);
ftp = (FtpWebRequest)FtpWebReque
ftp.UseBinary = true;
ftp.Credentials = new NetworkCredential(crdUsern
ftp.Method = WebRequestMethods.Ftp.Down
response = (FtpWebResponse)ftp.GetRes
ftpStream = response.GetResponseStream
int bufferSize = 2048;
int readCount = 0;
byte[] buffer = new byte[bufferSize];
readCount = ftpStream.Read(buffer, 0, readCount); <======= Line that throws the Error
while (readCount > 0)
{
fs.Write(buffer, 0, readCount);
readCount = ftpStream.Read(buffer, 0, bufferSize);
System.Console.WriteLine(r
}
}
catch (Exception ex)
{
StringBuilder strError = new StringBuilder();
strError.Append("FTP_Error
strError.Append(DateTime.N
strError.Append(".txt");
Database.Log_Error(strErro
}
finally
{
ftpStream.Close();
fs.Close();
response.Close();
}
} // End of Download()
The line indicated in the code that throws an error says that connection is closed. There may or may not be some error elsewhere in the code that is causing an error at this line. But I am unfamiliar with this type of process and don't know where to look to find answers.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Business Accounts
Answer for Membership
by: josephdaviskcrmPosted on 2008-07-30 at 23:28:36ID: 22127350
Figured it out. I needed to set readCount = 2048 to begin with instead of 0.