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.Crea te("ftp://<serverIP>/inbox/" & Filename)
request.Method = WebRequestMetho ds.Ftp.UploadFi le
request.UseBina ry = True
request.Credent ials = New NetworkCredenti al("username",
"password")
Dim sourcestream As New StreamReader(Ou tBox & Filename)
Dim Filecontents As Byte()
Filecontents =
Encoding.UTF8.G etBytes(sources tream.ReadToEnd ())
sourcestream.Cl ose()
request.Content Length = Filecontents.Le ngth
Dim requestStream = request.GetRequ estStream()
requestStream.W rite(Fileconten ts, 0, Filecontents.Le ngth)
requestStream.C lose()
Dim response = request.GetResp onse()
response.Close( )
File.Delete(Out Box & 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
to upload some files:
Dim Filename As String = Dir(OutBox)
Do
Dim request As FtpWebRequest =
WebRequest.Crea te("ftp://<serverIP>/inbox/" & Filename)
request.Method = WebRequestMetho ds.Ftp.UploadFi le
request.UseBina ry = True
request.Credent ials = New NetworkCredenti al("username",
"password")
Dim sourcestream As New StreamReader(Ou tBox & Filename)
Dim Filecontents As Byte()
Filecontents =
Encoding.UTF8.G etBytes(sources tream.ReadToEnd ())
sourcestream.Cl ose()
request.Content Length = Filecontents.Le ngth
Dim requestStream = request.GetRequ estStream()
requestStream.W rite(Fileconten ts, 0, Filecontents.Le ngth)
requestStream.C lose()
Dim response = request.GetResp onse()
response.Close( )
File.Delete(Out Box & 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
Comment