Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7180077
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T17:16:21+00:00 2026-05-28T17:16:21+00:00

I am trying to copy file(s) using webrequest inside WCF. I need some suggestions.

  • 0

I am trying to copy file(s) using webrequest inside WCF. I need some suggestions. Are there better ways of doing this?

What kind of security issues am I going to face here?

Can I do it inside WCF or is making it separate better?

public void InsertOccured(string Name)
{
  //  Console.WriteLine("Insert Occured",Name);
    Console.WriteLine("Insert Occured, {0}", Name);
   // FTP request to download the file from FTP Location
    FtpWebRequest reqFTP;

    try
    {
        string FilePath;
        string FileName = Name;

        //use Switch statement to identify the ftpServerIP

        FileStream outputStream = new FileStream(FilePath + "\\" + FileName, FileMode.Create);
        reqFTP= (FtpWebRequest)FtpWebRequest.Create(new Uri("ftp://" + ftpserverIp + FileName));
        reqFTP.Method= WebRequestMethods.Ftp.DownloadFile;
        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();

    }
    catch (Exception ex)
    {
        Console.WriteLine(ex);
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T17:16:22+00:00Added an answer on May 28, 2026 at 5:16 pm

    Its always better to make it separate but I don’t know much about security issues with WCF however you could use this code to read responseStream, you should be using “using” to have framework manage disposing the stream properly

        try
            {
                byte[] buffer = new byte[4155]; 
                byte[] newBuffer;
                int readSize = 0;
                FileStream outputStream = new FileStream(FilePath + "\\" + FileName, FileMode.Create);
                int i = 0;
                using (Stream input = response.GetResponseStream())
                {
                        readSize = input.Read(buffer, 0, buffer.Length);
                        if (readSize > 0)
                        {
                            newBuffer = new byte[readSize];
                            Array.Copy(buffer, newBuffer, readSize);
                            outputStream.Write(newBuffer.ToArray(), 0, readSize);
                        }
                    outputStream.Close();
                } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to copy some files from one network share to another using File::Copy.
I'm trying to copy a used repository by using svnsync (I'm doing it this
I'm trying to copy a file from one location to another using SHFileOperation: SHFILEOPSTRUCT
I'm trying to upload a file using JavaFX using the HttpRequest. For this purpose
I'm trying to copy a single file using copy-item to a remote computer using
I'm using Windows 7 Ultimate, trying to manually copy a file into the GAC.
I am trying to copy a file from my remote server to my local.
I'm trying to copy both an image from a file and text from a
I'm trying to write a simple ruby script that will copy a file to
I am trying to read a single file from a java.util.zip.ZipInputStream , and copy

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.