Home All Groups Group Topic Archive Search About

FTP Programming Question

Author
2 Mar 2007 9:46 PM
pbd22
Hi.

I have an FTP programming question.
I want the total size of a file being uploaded "before" it is
completely uploaded to the server. I need this for the condition:
when currentbytes = totalbytes, do something. But,
it seems that the filesize before it hits the FTP server is not equal
to the same file's bytes on the other end. I am using either of the
two methods to get the filesize "before" it lands on the remote
server:

Dim postedFile As HttpPostedFile = myfiles(count)
postedFile.InputStream.Length

-- or --

postedFile.ContentLength

and the below method to get the filesize once it is on the FTP server
(and fully uploaded):

Public Function GetFileSize(ByVal sFileName As String) As Long

            If (Not (m_bLoggedIn)) Then
                Login()
            End If

            SendCommand(("SIZE " + sFileName))

            Dim size As Long = 0

            If (m_iRetValue = 213) Then
                size = Int64.Parse(m_sReply.Substring(4))
            Else
                Throw New IOException(m_sReply.Substring(4))
            End If

            Return size

End Function

Does anybody see why this could be happening? Has anybody else noticed
this distinction?

Thanks in advance.

Author
2 Mar 2007 11:16 PM
Amil Hanish
Forget doing FTP using .net...much easier.  use the free API at:

http://www.enterprisedt.com/products/edtftpnetexpress/overview.html

I've used this before...very nice.

Amil

Show quote
"pbd22" <dush***@gmail.com> wrote in message
news:1172872001.545493.260010@8g2000cwh.googlegroups.com...
>
> Hi.
>
> I have an FTP programming question.
> I want the total size of a file being uploaded "before" it is
> completely uploaded to the server. I need this for the condition:
> when currentbytes = totalbytes, do something. But,
> it seems that the filesize before it hits the FTP server is not equal
> to the same file's bytes on the other end. I am using either of the
> two methods to get the filesize "before" it lands on the remote
> server:
>
> Dim postedFile As HttpPostedFile = myfiles(count)
> postedFile.InputStream.Length
>
> -- or --
>
> postedFile.ContentLength
>
> and the below method to get the filesize once it is on the FTP server
> (and fully uploaded):
>
> Public Function GetFileSize(ByVal sFileName As String) As Long
>
>            If (Not (m_bLoggedIn)) Then
>                Login()
>            End If
>
>            SendCommand(("SIZE " + sFileName))
>
>            Dim size As Long = 0
>
>            If (m_iRetValue = 213) Then
>                size = Int64.Parse(m_sReply.Substring(4))
>            Else
>                Throw New IOException(m_sReply.Substring(4))
>            End If
>
>            Return size
>
> End Function
>
> Does anybody see why this could be happening? Has anybody else noticed
> this distinction?
>
> Thanks in advance.
>
Author
3 Mar 2007 7:33 AM
Jon Skeet [C# MVP]
Amil Hanish <amilhan***@hotmail.com> wrote:
> Forget doing FTP using .net...much easier.  use the free API at:
>
> http://www.enterprisedt.com/products/edtftpnetexpress/overview.html
>
> I've used this before...very nice.

I don't see a free version there. I see a 30 day trial version, but not
a free one.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet   Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Author
3 Mar 2007 10:08 PM
rwaldicott
Show quote
On Mar 2, 5:16 pm, "Amil Hanish" <amilhan***@hotmail.com> wrote:
> Forget doing FTP using .net...much easier.  use the free API at:
>
> http://www.enterprisedt.com/products/edtftpnetexpress/overview.html
>
> I've used this before...very nice.
>
> Amil
>
> "pbd22" <dush***@gmail.com> wrote in message
>
> news:1172872001.545493.260010@8g2000cwh.googlegroups.com...
>
>
>
> > Hi.
>
> > I have an FTP programming question.
> > I want the total size of a file being uploaded "before" it is
> > completely uploaded to the server. I need this for the condition:
> > when currentbytes = totalbytes, do something. But,
> > it seems that the filesize before it hits the FTP server is not equal
> > to the same file's bytes on the other end. I am using either of the
> > two methods to get the filesize "before" it lands on the remote
> > server:
>
> > Dim postedFile As HttpPostedFile = myfiles(count)
> > postedFile.InputStream.Length
>
> > -- or --
>
> > postedFile.ContentLength
>
> > and the below method to get the filesize once it is on the FTP server
> > (and fully uploaded):
>
> > Public Function GetFileSize(ByVal sFileName As String) As Long
>
> >            If (Not (m_bLoggedIn)) Then
> >                Login()
> >            End If
>
> >            SendCommand(("SIZE " + sFileName))
>
> >            Dim size As Long = 0
>
> >            If (m_iRetValue = 213) Then
> >                size = Int64.Parse(m_sReply.Substring(4))
> >            Else
> >                Throw New IOException(m_sReply.Substring(4))
> >            End If
>
> >            Return size
>
> > End Function
>
> > Does anybody see why this could be happening? Has anybody else noticed
> > this distinction?
>
> > Thanks in advance.

another API to consider ... Secure FTP Factory for .NET

http://www.jscape.com/sftpdotnet/
Author
4 Mar 2007 4:03 AM
pbd22
On Mar 3, 2:08 pm, rwaldic***@gmail.com wrote:
Show quote
> On Mar 2, 5:16 pm, "Amil Hanish" <amilhan***@hotmail.com> wrote:
>
>
>
> > Forget doing FTP using .net...much easier.  use the free API at:
>
> >http://www.enterprisedt.com/products/edtftpnetexpress/overview.html
>
> > I've used this before...very nice.
>
> > Amil
>
> > "pbd22" <dush***@gmail.com> wrote in message
>
> >news:1172872001.545493.260010@8g2000cwh.googlegroups.com...
>
> > > Hi.
>
> > > I have an FTP programming question.
> > > I want the total size of a file being uploaded "before" it is
> > > completely uploaded to the server. I need this for the condition:
> > > when currentbytes = totalbytes, do something. But,
> > > it seems that the filesize before it hits the FTP server is not equal
> > > to the same file's bytes on the other end. I am using either of the
> > > two methods to get the filesize "before" it lands on the remote
> > > server:
>
> > > Dim postedFile As HttpPostedFile = myfiles(count)
> > > postedFile.InputStream.Length
>
> > > -- or --
>
> > > postedFile.ContentLength
>
> > > and the below method to get the filesize once it is on the FTP server
> > > (and fully uploaded):
>
> > > Public Function GetFileSize(ByVal sFileName As String) As Long
>
> > >            If (Not (m_bLoggedIn)) Then
> > >                Login()
> > >            End If
>
> > >            SendCommand(("SIZE " + sFileName))
>
> > >            Dim size As Long = 0
>
> > >            If (m_iRetValue = 213) Then
> > >                size = Int64.Parse(m_sReply.Substring(4))
> > >            Else
> > >                Throw New IOException(m_sReply.Substring(4))
> > >            End If
>
> > >            Return size
>
> > > End Function
>
> > > Does anybody see why this could be happening? Has anybody else noticed
> > > this distinction?
>
> > > Thanks in advance.
>
> another API to consider ... Secure FTP Factory for .NET
>
> http://www.jscape.com/sftpdotnet/


Thanks all for your replies and suggestions. Before I start to check
out alternative APIs, would somebly mind addressing the original
question? Why does the file have different byte counts when it hits
the web server and then, again, once it has landed on the remote FTP
server?

thanks.
Author
4 Mar 2007 12:11 PM
rwaldicott
Show quote
On Mar 3, 10:03 pm, "pbd22" <dush***@gmail.com> wrote:
> On Mar 3, 2:08 pm, rwaldic***@gmail.com wrote:
>
>
>
> > On Mar 2, 5:16 pm, "Amil Hanish" <amilhan***@hotmail.com> wrote:
>
> > > Forget doing FTP using .net...much easier.  use the free API at:
>
> > >http://www.enterprisedt.com/products/edtftpnetexpress/overview.html
>
> > > I've used this before...very nice.
>
> > > Amil
>
> > > "pbd22" <dush***@gmail.com> wrote in message
>
> > >news:1172872001.545493.260010@8g2000cwh.googlegroups.com...
>
> > > > Hi.
>
> > > > I have an FTP programming question.
> > > > I want the total size of a file being uploaded "before" it is
> > > > completely uploaded to the server. I need this for the condition:
> > > > when currentbytes = totalbytes, do something. But,
> > > > it seems that the filesize before it hits the FTP server is not equal
> > > > to the same file's bytes on the other end. I am using either of the
> > > > two methods to get the filesize "before" it lands on the remote
> > > > server:
>
> > > > Dim postedFile As HttpPostedFile = myfiles(count)
> > > > postedFile.InputStream.Length
>
> > > > -- or --
>
> > > > postedFile.ContentLength
>
> > > > and the below method to get the filesize once it is on the FTP server
> > > > (and fully uploaded):
>
> > > > Public Function GetFileSize(ByVal sFileName As String) As Long
>
> > > >            If (Not (m_bLoggedIn)) Then
> > > >                Login()
> > > >            End If
>
> > > >            SendCommand(("SIZE " + sFileName))
>
> > > >            Dim size As Long = 0
>
> > > >            If (m_iRetValue = 213) Then
> > > >                size = Int64.Parse(m_sReply.Substring(4))
> > > >            Else
> > > >                Throw New IOException(m_sReply.Substring(4))
> > > >            End If
>
> > > >            Return size
>
> > > > End Function
>
> > > > Does anybody see why this could be happening? Has anybody else noticed
> > > > this distinction?
>
> > > > Thanks in advance.
>
> > another API to consider ... Secure FTP Factory for .NET
>
> >http://www.jscape.com/sftpdotnet/
>
> Thanks all for your replies and suggestions. Before I start to check
> out alternative APIs, would somebly mind addressing the original
> question? Why does the file have different byte counts when it hits
> the web server and then, again, once it has landed on the remote FTP
> server?
>
> thanks.

the resulting filesize should be the same if you are transferring in
binary mode.  If you are transferring in ASCII mode then the filesize
could get change due to difference in line terminators between local
machine and FTP server.  In whichever client you are using make sure
you are using binary mode.

AddThis Social Bookmark Button