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

  • Home
  • SEARCH
  • 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 7003977
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:08:21+00:00 2026-05-27T21:08:21+00:00

This is very specific. I need help with using a C# function in my

  • 0

This is very specific. I need help with using a C# function in my my VB.Net program The function is in a DLL and the code is below:

public void UploadData(string FTPUri, string FilePath, string FileName,
                       string UserName, string Password)
{
    StatusUp = new Int64[2];

    reqFTP = (FtpWebRequest)FtpWebRequest.Create(FTPUri + FileName);
    reqFTP.Method = WebRequestMethods.Ftp.UploadFile;
    reqFTP.UseBinary = true;
    reqFTP.Credentials = new NetworkCredential(UserName, Password);

    FileInfo fileInf = new FileInfo(FilePath);

    FileStream fs = fileInf.OpenRead();

    // modifyied code
    int bytesSize = 0;
    byte[] UpBuffer = new byte[2048];

    ftpStream = reqFTP.GetRequestStream();

    bytesSize = fs.Read(UpBuffer, 0, UpBuffer.Length);

    while ((bytesSize = fs.Read(UpBuffer, 0, UpBuffer.Length)) > 0)
    {
        StatusUp[0] = StatusUp[0] + UpBuffer.Length;
        StatusUp[1] = fileInf.Length;// +startPointInt;

        ftpStream.Write(UpBuffer, 0, bytesSize);
    }

    fs.Close();
    ftpStream.Close();
}

In my vb.net program I am calling it like this:

Dim FtpUpload As FTPUtility.ftpUtility = New FTPUtility.ftpUtility
FtpUpload.UploadData("ftp://ftp.xxx.xx", "C:\winzip.log", "/winzip.log", "uploader", "xxxx")

It works ok except it is 2 bytes short when it is done. I don’t know enough C# to figure out if the C# code is wrong (I didn’t write it and the guy who did has left the company), but somewhere it appears that it is not closing the file or something.

Any ideas?

  • 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-27T21:08:21+00:00Added an answer on May 27, 2026 at 9:08 pm
    bytesSize = fs.Read(UpBuffer, 0, UpBuffer.Length);
    
    while ((bytesSize = fs.Read(UpBuffer, 0, UpBuffer.Length)) > 0)
    {
        StatusUp[0] = StatusUp[0] + UpBuffer.Length;
        // etc..
    }
    

    Two red flags here. The first one is the cause of your problem, the extra fs.Read() call before you enter the while loop. That’s 2048 bytes you don’t use and don’t upload. Just delete that line. You avoid these kind of bugs by using for (;;) and break.

    The StatusUp[0] assignment looks bad, you should add bytesSize, not UpBuffer.Length. It isn’t otherwise obvious what side-effects that has.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This very simple code: #include <iostream> using namespace std; void exec(char* option) { cout
I've written this very simple function to replace a file extension using LINQ in
This question might seem very specific but I am in need of some ideas
This is a very specific question regarding MySQL as implemented in WordPress . I'm
This is a very specific question which will probably earn me the tumbleweed badge,
This is a very specific question for a Google Chrome extension. http://www.meebo.com/mobile/ This page
I apologise in advance if this question isn't very specific. Would it be possible
This is a very narrow and specific question, but I know there are someone
First of I'm very sorry but this questions is not so so specific. All
This very simple code gives me tons of errors: #include <iostream> #include <string> int

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.