FTP Upload (Encoding) problem

J

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
 
T

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:
 
J

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
 
J

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

_______________________________________________
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top