|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
FTP Upload (Encoding) problemto 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 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 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 > 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 >> > >
Array in Structure
Regular expression to match person's name Problem with ComboBox execution from command line Help! pumping wait primitives - what is that? Run an Access report in a VB .Net application Windows Service losing variable value? How to detect if program execution is in debug mode? Form Layout TimeSpan issue |
|||||||||||||||||||||||