Download part of bytes FtpWebRequest c#

Tags: c#

I'm in the situation where I need live logs, but they cannot be added to a database table. I need them live, so I figure instead of downloading the entire log file every 25 seconds, I should download part of the bytes. I don't see any parameters in the FtpWebRequest where I can specify this.

So the question is: How do I download part of a file via FtpWebRequest? (eg. the first 1024 bytes)


if i understand you right then You can just Keep Downloading Till The Download hit the Size of bytes you want then you can stop your download and save the actual bytes


create the byte[] you want for example :

byte[] buffer = new byte[2048];

you can download via FtpwebRequest using :

request.Method = WebRequestMethods.Ftp.DownloadFile;

then keep writing the bytes in the buffer

 private void DownloadFile(string userName, string password, string ftpSourceFilePath, string localDestinationFilePath)
        int bytesRead = 0;
        byte[] buffer = new byte[2048];

        FtpWebRequest request = CreateFtpWebRequest(ftpSourceFilePath, userName, password, true);
        request.Method = WebRequestMethods.Ftp.DownloadFile;

        Stream reader = request.GetResponse().GetResponseStream();
        FileStream fileStream = new FileStream(localDestinationFilePath, FileMode.Create);

        while (true)
            bytesRead = reader.Read(buffer, 0, buffer.Length);

            if (bytesRead == 0)

            fileStream.Write(buffer, 0, bytesRead);
By : Buffer_z

The root problem: you're trying to assign value of instances in theirselves. Note: what you're doing is still wrong, otherObject is a object, but it's a String object and it's not referring to the current foo's instance (this).

this.nextDev = otherObject

Other problem is that you're calling String().checkThreshold, but not foo().checkThreshold. You can check that at your statements:

successorList = this.nextDev.split(",");
for (var i = 0; i < successorList.length; i++) {

As you can see you're iterating string literals. String().split returns a object with string literals back, not a list with foo()'s.

/* confirm that the successorList is a array object */
successorList instanceof Array; // true
/* confirm that the first successorList's item is a string object */
typeof successorList[0] === "string"; // true

I'm basically not sure about what's your objective. It looks like you've a extra-ordinary giant confusion between String objects and objects. Maybe you want to store nextDev out of foo(), and at nextDev you want to store a Array object containing instances of foo? Then try:

var devs = [];

function foo(string) {

foo.prototype = {
    checkOtherObjects: function() {
        var me = this;
        var myIndex;
        var i = 0, len = devs.length;
        for (; i < len; ++i) {
            if (devs[i] === me) {
                myIndex = i;
        for (i = myIndex + 1; i < len; ++i)

This video can help you solving your question :)
By: admin