hi i m working on an ftp application in c# in which i have to download a file and upload the same file. here is my code for download data.
Code:
try
            {
                
                textBox1.Text = ftpServerIP;
                textBox2.Text = ftpUserID;
                textBox3.Text = ftpPassword;
                FtpWebRequest reqFTP;
                //filePath = <<The full path where the file is to be created.>>, 
                //fileName = <<Name of the file to be created(Need not be the name of the file on FTP server).>>
                FileStream outputStream = new FileStream(filePath + "\\" + fileName, FileMode.Create);
                Uri downloadPath = new Uri("ftp://" + ftpServerIP + "/" + client_fileName);
                reqFTP = (FtpWebRequest)FtpWebRequest.Create(downloadPath);
                reqFTP.Method = WebRequestMethods.Ftp.DownloadFile;
                reqFTP.UseBinary = true;
                reqFTP.Credentials = new NetworkCredential(ftpUserID, ftpPassword);
                FtpWebResponse response = (FtpWebResponse)reqFTP.GetResponse();
                Stream ftpStream = response.GetResponseStream();
                long cl = response.ContentLength;
                int bufferSize = 2048;
                int readCount;
                byte[] buffer = new byte[bufferSize];

                readCount = ftpStream.Read(buffer, 0, bufferSize);
                while (readCount > 0)
                {
                    outputStream.Write(buffer, 0, readCount);
                    readCount = ftpStream.Read(buffer, 0, bufferSize);
                }

                ftpStream.Close();
                outputStream.Close();
                response.Close();
                DataBaseOperations db = new DataBaseOperations();
                templist = db.GetData();
                dataGridView1.DataSource = templist;
                dataGridView1.Refresh();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
and my uploading function is
Code:
public void Upload(string filename, string url)
        {
            FileInfo fileInf = new FileInfo(filename+"\\test.s3db");
            string uri = "ftp://" + url + "/" +"/public_html/RemoteDic/" + " test.s3db";
            FtpWebRequest reqFTP;
            reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(uri));
            reqFTP.Credentials = new NetworkCredential(ftpUserID, ftpPassword);
            reqFTP.KeepAlive = false;
            reqFTP.Method = WebRequestMethods.Ftp.UploadFile;
            reqFTP.UseBinary = true;
            reqFTP.ContentLength = fileInf.Length;
            FileStream inputStream = fileInf.OpenRead();
            using (var outputStream = reqFTP.GetRequestStream())
            {
                var buffer = new byte[1024];
                int totalReadBytesCount = 0;
                int readBytesCount;
                while ((readBytesCount = inputStream.Read(buffer, 0, buffer.Length)) > 0)
                {
                    outputStream.Write(buffer, 0, readBytesCount);
                    totalReadBytesCount += readBytesCount;
                    var progress = totalReadBytesCount * 100.0 / inputStream.Length;
                   
      
                }
                outputStream.Close();
            }
            inputStream.Close();
        }
but when i run the program i get an error
"The process cannot access the file 'E:\rafay zia mir\web connect\web connect\bin\Debug\test.s3db' because it is being used by another process."
but in the downloading section all streams are closed after the file has been downloaded.