Home All Groups Group Topic Archive Search About

FTP Upload (Encoding) problem

Author
12 Aug 2006 5:17 PM
Jerry Spence1
I have the following code (copied from the web somewhere) which I am using
to upload some files:

            Dim Filename As String = Dir(OutBox)
            Do
                Dim request As FtpWebRequest =
WebRequest.Create("ftp://<serverIP>/inbox/" & Filename)
                request.Method = WebRequestMethods.Ftp.UploadFile
                request.UseBinary = True

                request.Credentials = New NetworkCredential("username",
"password")

                Dim sourcestream As New StreamReader(OutBox & Filename)
                Dim Filecontents As Byte()
                Filecontents =
Encoding.UTF8.GetBytes(sourcestream.ReadToEnd())
                sourcestream.Close()
                request.ContentLength = Filecontents.Length

                Dim requestStream = request.GetRequestStream()
                requestStream.Write(Filecontents, 0, Filecontents.Length)
                requestStream.Close()
                Dim response = request.GetResponse()
                response.Close()
                File.Delete(OutBox & Filename)
                Filename = Dir()
                If Filename = "" Then Exit Do
            Loop

I am copying jpg files so need a binary transfer. My problem is with the
encoding line. I don't want any encoding - I just want to copy the file as
it is. What should this line read?

Or, of course, is there a better way to do it?

-Jerry

Author
12 Aug 2006 7:26 PM
tommaso.gastaldi
Hi jerry,

if you do not need to take control of the stream
why do not make life easier with (vb2005)

My.Computer.Network.UploadFile(sourcefile, TargetServerAndFileName,
UserId, Password, true, 1000)

-tom

Jerry Spence1 ha scritto:

Show quoteHide quote
> I have the following code (copied from the web somewhere) which I am using
> to upload some files:
>
>             Dim Filename As String = Dir(OutBox)
>             Do
>                 Dim request As FtpWebRequest =
> WebRequest.Create("ftp://<serverIP>/inbox/" & Filename)
>                 request.Method = WebRequestMethods.Ftp.UploadFile
>                 request.UseBinary = True
>
>                 request.Credentials = New NetworkCredential("username",
> "password")
>
>                 Dim sourcestream As New StreamReader(OutBox & Filename)
>                 Dim Filecontents As Byte()
>                 Filecontents =
> Encoding.UTF8.GetBytes(sourcestream.ReadToEnd())
>                 sourcestream.Close()
>                 request.ContentLength = Filecontents.Length
>
>                 Dim requestStream = request.GetRequestStream()
>                 requestStream.Write(Filecontents, 0, Filecontents.Length)
>                 requestStream.Close()
>                 Dim response = request.GetResponse()
>                 response.Close()
>                 File.Delete(OutBox & Filename)
>                 Filename = Dir()
>                 If Filename = "" Then Exit Do
>             Loop
>
> I am copying jpg files so need a binary transfer. My problem is with the
> encoding line. I don't want any encoding - I just want to copy the file as
> it is. What should this line read?
>
> Or, of course, is there a better way to do it?
>
> -Jerry
Author
13 Aug 2006 5:30 AM
Jerry Spence1
Thanks a lot Tom - I was sort of aware of that command in VB2005, but I
hadn't appreciated its power.

As a tip for others who come across this thread, the destination server must
be ftp://<ipaddress> or http://<ipaddress> to get it to work.

-Jerry




<tommaso.gasta***@uniroma1.it> wrote in message
Show quoteHide quote
news:1155410813.523301.280520@b28g2000cwb.googlegroups.com...
> Hi jerry,
>
> if you do not need to take control of the stream
> why do not make life easier with (vb2005)
>
> My.Computer.Network.UploadFile(sourcefile, TargetServerAndFileName,
> UserId, Password, true, 1000)
>
> -tom
>
> Jerry Spence1 ha scritto:
>
>> I have the following code (copied from the web somewhere) which I am
>> using
>> to upload some files:
>>
>>             Dim Filename As String = Dir(OutBox)
>>             Do
>>                 Dim request As FtpWebRequest =
>> WebRequest.Create("ftp://<serverIP>/inbox/" & Filename)
>>                 request.Method = WebRequestMethods.Ftp.UploadFile
>>                 request.UseBinary = True
>>
>>                 request.Credentials = New NetworkCredential("username",
>> "password")
>>
>>                 Dim sourcestream As New StreamReader(OutBox & Filename)
>>                 Dim Filecontents As Byte()
>>                 Filecontents =
>> Encoding.UTF8.GetBytes(sourcestream.ReadToEnd())
>>                 sourcestream.Close()
>>                 request.ContentLength = Filecontents.Length
>>
>>                 Dim requestStream = request.GetRequestStream()
>>                 requestStream.Write(Filecontents, 0, Filecontents.Length)
>>                 requestStream.Close()
>>                 Dim response = request.GetResponse()
>>                 response.Close()
>>                 File.Delete(OutBox & Filename)
>>                 Filename = Dir()
>>                 If Filename = "" Then Exit Do
>>             Loop
>>
>> I am copying jpg files so need a binary transfer. My problem is with the
>> encoding line. I don't want any encoding - I just want to copy the file
>> as
>> it is. What should this line read?
>>
>> Or, of course, is there a better way to do it?
>>
>> -Jerry
>
Author
18 Aug 2006 4:36 AM
Jerry Spence1
Another tip is that I couldn't get ftp://123.456.789.012 to work. I don't
know why, but I found that if I put a reference in my HOSTS table to a name
(myserver) and then ftp://myserver worked just fine

-Jerry

_______________________________________________

Show quoteHide quote
"Jerry Spence1" <jerry.spe***@somewhere.com> wrote in message
news:44deb910$0$60313$ed2619ec@ptn-nntp-reader03.plus.net...
> Thanks a lot Tom - I was sort of aware of that command in VB2005, but I
> hadn't appreciated its power.
>
> As a tip for others who come across this thread, the destination server
> must be ftp://<ipaddress> or http://<ipaddress> to get it to work.
>
> -Jerry
>
>
>
>
> <tommaso.gasta***@uniroma1.it> wrote in message
> news:1155410813.523301.280520@b28g2000cwb.googlegroups.com...
>> Hi jerry,
>>
>> if you do not need to take control of the stream
>> why do not make life easier with (vb2005)
>>
>> My.Computer.Network.UploadFile(sourcefile, TargetServerAndFileName,
>> UserId, Password, true, 1000)
>>
>> -tom
>>
>> Jerry Spence1 ha scritto:
>>
>>> I have the following code (copied from the web somewhere) which I am
>>> using
>>> to upload some files:
>>>
>>>             Dim Filename As String = Dir(OutBox)
>>>             Do
>>>                 Dim request As FtpWebRequest =
>>> WebRequest.Create("ftp://<serverIP>/inbox/" & Filename)
>>>                 request.Method = WebRequestMethods.Ftp.UploadFile
>>>                 request.UseBinary = True
>>>
>>>                 request.Credentials = New NetworkCredential("username",
>>> "password")
>>>
>>>                 Dim sourcestream As New StreamReader(OutBox & Filename)
>>>                 Dim Filecontents As Byte()
>>>                 Filecontents =
>>> Encoding.UTF8.GetBytes(sourcestream.ReadToEnd())
>>>                 sourcestream.Close()
>>>                 request.ContentLength = Filecontents.Length
>>>
>>>                 Dim requestStream = request.GetRequestStream()
>>>                 requestStream.Write(Filecontents, 0,
>>> Filecontents.Length)
>>>                 requestStream.Close()
>>>                 Dim response = request.GetResponse()
>>>                 response.Close()
>>>                 File.Delete(OutBox & Filename)
>>>                 Filename = Dir()
>>>                 If Filename = "" Then Exit Do
>>>             Loop
>>>
>>> I am copying jpg files so need a binary transfer. My problem is with the
>>> encoding line. I don't want any encoding - I just want to copy the file
>>> as
>>> it is. What should this line read?
>>>
>>> Or, of course, is there a better way to do it?
>>>
>>> -Jerry
>>
>
>