|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Https: with VBI'm looking for guidance to show developers information about implementing
https using VB so that an application which needs to transfer files securely from within a VB client app can do so using https: I'm aware the capability is available but need some guidance about where to find the detailed information so I can help a developer learn something they do not already know how to do. Any help appreciated. Hi David,
Play with this.... Dim crdential As New System.Net.NetworkCredential("UserName", "Password") UploadFile("c:\mylocalfolder\mylocalfile.txt", "https://thewebsite.com/thedirectory/mylocalfile.txt", crdential) ---------------------------------- Friend Function UploadFile(ByVal SourceLocation As String, ByVal DestinationLocation As String, ByVal Credential As System.Net.NetworkCredential) As Boolean Dim Response As String = Nothing, FileSize As Double = 0 Try UploadFile = False If SourceLocation.ToString.Trim <> "" And DestinationLocation.ToString.Trim <> "" Then 'To set Upload settings Dim UploadRequest As System.Net.HttpWebRequest = CType(System.Net.WebRequest.Create(New Uri(DestinationLocation.ToString.Trim)), System.Net.HttpWebRequest) UploadRequest.Credentials = Credential UploadRequest.Timeout = 60000000 UploadRequest.Method = "PUT" UploadRequest.ContentLength = New System.IO.FileInfo(SourceLocation.ToString.Trim).Length FileSize = UploadRequest.ContentLength.ToString.Trim 'To set Upload Stream settings Dim SourceStream As New System.IO.FileStream(SourceLocation.ToString.Trim, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.ReadWrite) Dim RequestStream As System.IO.Stream = UploadRequest.GetRequestStream() Dim Buffer(4095) As Byte Dim Position As Integer = 0, ivlLoop As Integer = 0, CurLocation As Integer = 0 Position = SourceStream.Read(Buffer, 0, Buffer.Length) While Position <> 0 RequestStream.Write(Buffer, 0, Position) Position = SourceStream.Read(Buffer, 0, Buffer.Length) CurLocation += Position End While 'To upload Stream on Remote system Dim WebResponse As System.Net.HttpWebResponse = CType(UploadRequest.GetResponse(), System.Net.HttpWebResponse) Dim ResponseReader As New System.IO.StreamReader(WebResponse.GetResponseStream()) Response = ResponseReader.ReadToEnd() UploadFile = True RequestStream.Close() UploadRequest = Nothing SourceStream = Nothing RequestStream = Nothing WebResponse = Nothing ResponseReader = Nothing ElseIf SourceLocation.ToString.Trim = "" Then Call MsgBox("Source Location is missing") ElseIf DestinationLocation.ToString.Trim = "" Then Call MsgBox("Destination Location is missing") End If Catch ex As Exception Call MsgBox(ex.ToString) End Try End Function -- Show quoteHide quoteGet a powerful web, database, application, and email hosting with KJM Solutions http://www.kjmsolutions.com "David B" <Dav***@discussions.microsoft.com> wrote in message news:7BAE497C-D8CA-4238-8CFE-1BCDC5446DA3@microsoft.com... > I'm looking for guidance to show developers information about implementing > https using VB so that an application which needs to transfer files > securely > from within a VB client app can do so using https: > > I'm aware the capability is available but need some guidance about where > to > find the detailed information so I can help a developer learn something > they > do not already know how to do. > > Any help appreciated. > Hi. Thanks for this response.
I presume with just a little effort we could reverse the direction of this example and have this work for downloading a file TO a client with this function in the client-side app? (The PUT becomes a GET, etc?). Again, trying to provide guidance to the developers for them to work this out. Show quoteHide quote "vbnetdev" wrote: > Hi David, > > Play with this.... > > Dim crdential As New System.Net.NetworkCredential("UserName", "Password") > UploadFile("c:\mylocalfolder\mylocalfile.txt", > "https://thewebsite.com/thedirectory/mylocalfile.txt", crdential) > > ---------------------------------- > Friend Function UploadFile(ByVal SourceLocation As String, ByVal > DestinationLocation As String, ByVal Credential As > System.Net.NetworkCredential) As Boolean > Dim Response As String = Nothing, FileSize As Double = 0 > Try > UploadFile = False > If SourceLocation.ToString.Trim <> "" And > DestinationLocation.ToString.Trim <> "" Then > 'To set Upload settings > Dim UploadRequest As System.Net.HttpWebRequest = > CType(System.Net.WebRequest.Create(New > Uri(DestinationLocation.ToString.Trim)), System.Net.HttpWebRequest) > UploadRequest.Credentials = Credential > UploadRequest.Timeout = 60000000 > UploadRequest.Method = "PUT" > UploadRequest.ContentLength = New > System.IO.FileInfo(SourceLocation.ToString.Trim).Length > FileSize = UploadRequest.ContentLength.ToString.Trim > > > 'To set Upload Stream settings > Dim SourceStream As New > System.IO.FileStream(SourceLocation.ToString.Trim, System.IO.FileMode.Open, > System.IO.FileAccess.Read, System.IO.FileShare.ReadWrite) > Dim RequestStream As System.IO.Stream = > UploadRequest.GetRequestStream() > Dim Buffer(4095) As Byte > Dim Position As Integer = 0, ivlLoop As Integer = 0, > CurLocation As Integer = 0 > Position = SourceStream.Read(Buffer, 0, Buffer.Length) > > While Position <> 0 > RequestStream.Write(Buffer, 0, Position) > Position = SourceStream.Read(Buffer, 0, Buffer.Length) > CurLocation += Position > End While > > 'To upload Stream on Remote system > Dim WebResponse As System.Net.HttpWebResponse = > CType(UploadRequest.GetResponse(), System.Net.HttpWebResponse) > Dim ResponseReader As New > System.IO.StreamReader(WebResponse.GetResponseStream()) > Response = ResponseReader.ReadToEnd() > UploadFile = True > > RequestStream.Close() > UploadRequest = Nothing > SourceStream = Nothing > RequestStream = Nothing > WebResponse = Nothing > ResponseReader = Nothing > ElseIf SourceLocation.ToString.Trim = "" Then > Call MsgBox("Source Location is missing") > ElseIf DestinationLocation.ToString.Trim = "" Then > Call MsgBox("Destination Location is missing") > End If > Catch ex As Exception > Call MsgBox(ex.ToString) > End Try > End Function > > > -- > Get a powerful web, database, application, and email hosting with KJM > Solutions > http://www.kjmsolutions.com > > > > "David B" <Dav***@discussions.microsoft.com> wrote in message > news:7BAE497C-D8CA-4238-8CFE-1BCDC5446DA3@microsoft.com... > > I'm looking for guidance to show developers information about implementing > > https using VB so that an application which needs to transfer files > > securely > > from within a VB client app can do so using https: > > > > I'm aware the capability is available but need some guidance about where > > to > > find the detailed information so I can help a developer learn something > > they > > do not already know how to do. > > > > Any help appreciated. > > > > > Are you asking me to come up with a sample to do this? I don't imagine it
would be difficult. The reason I gave you what I did was if you are trying to get your developers a starting point this should do it. If you are asking for someone to build it for them you need to email me off list (admin@nospamkjmsolutions.com (remove no spam)) to discuss this situation further. -- Show quoteHide quoteGet a powerful web, database, application, and email hosting with KJM Solutions http://www.kjmsolutions.com "David B" <Dav***@discussions.microsoft.com> wrote in message news:BA5FF97B-C8EE-4A1D-8982-6F10A031AB00@microsoft.com... > Hi. Thanks for this response. > > I presume with just a little effort we could reverse the direction of this > example and have this work for downloading a file TO a client with this > function in the client-side app? (The PUT becomes a GET, etc?). > > Again, trying to provide guidance to the developers for them to work this > out. > > "vbnetdev" wrote: > >> Hi David, >> >> Play with this.... >> >> Dim crdential As New System.Net.NetworkCredential("UserName", "Password") >> UploadFile("c:\mylocalfolder\mylocalfile.txt", >> "https://thewebsite.com/thedirectory/mylocalfile.txt", crdential) >> >> ---------------------------------- >> Friend Function UploadFile(ByVal SourceLocation As String, ByVal >> DestinationLocation As String, ByVal Credential As >> System.Net.NetworkCredential) As Boolean >> Dim Response As String = Nothing, FileSize As Double = 0 >> Try >> UploadFile = False >> If SourceLocation.ToString.Trim <> "" And >> DestinationLocation.ToString.Trim <> "" Then >> 'To set Upload settings >> Dim UploadRequest As System.Net.HttpWebRequest = >> CType(System.Net.WebRequest.Create(New >> Uri(DestinationLocation.ToString.Trim)), System.Net.HttpWebRequest) >> UploadRequest.Credentials = Credential >> UploadRequest.Timeout = 60000000 >> UploadRequest.Method = "PUT" >> UploadRequest.ContentLength = New >> System.IO.FileInfo(SourceLocation.ToString.Trim).Length >> FileSize = UploadRequest.ContentLength.ToString.Trim >> >> >> 'To set Upload Stream settings >> Dim SourceStream As New >> System.IO.FileStream(SourceLocation.ToString.Trim, >> System.IO.FileMode.Open, >> System.IO.FileAccess.Read, System.IO.FileShare.ReadWrite) >> Dim RequestStream As System.IO.Stream = >> UploadRequest.GetRequestStream() >> Dim Buffer(4095) As Byte >> Dim Position As Integer = 0, ivlLoop As Integer = 0, >> CurLocation As Integer = 0 >> Position = SourceStream.Read(Buffer, 0, Buffer.Length) >> >> While Position <> 0 >> RequestStream.Write(Buffer, 0, Position) >> Position = SourceStream.Read(Buffer, 0, >> Buffer.Length) >> CurLocation += Position >> End While >> >> 'To upload Stream on Remote system >> Dim WebResponse As System.Net.HttpWebResponse = >> CType(UploadRequest.GetResponse(), System.Net.HttpWebResponse) >> Dim ResponseReader As New >> System.IO.StreamReader(WebResponse.GetResponseStream()) >> Response = ResponseReader.ReadToEnd() >> UploadFile = True >> >> RequestStream.Close() >> UploadRequest = Nothing >> SourceStream = Nothing >> RequestStream = Nothing >> WebResponse = Nothing >> ResponseReader = Nothing >> ElseIf SourceLocation.ToString.Trim = "" Then >> Call MsgBox("Source Location is missing") >> ElseIf DestinationLocation.ToString.Trim = "" Then >> Call MsgBox("Destination Location is missing") >> End If >> Catch ex As Exception >> Call MsgBox(ex.ToString) >> End Try >> End Function >> >> >> -- >> Get a powerful web, database, application, and email hosting with KJM >> Solutions >> http://www.kjmsolutions.com >> >> >> >> "David B" <Dav***@discussions.microsoft.com> wrote in message >> news:7BAE497C-D8CA-4238-8CFE-1BCDC5446DA3@microsoft.com... >> > I'm looking for guidance to show developers information about >> > implementing >> > https using VB so that an application which needs to transfer files >> > securely >> > from within a VB client app can do so using https: >> > >> > I'm aware the capability is available but need some guidance about >> > where >> > to >> > find the detailed information so I can help a developer learn something >> > they >> > do not already know how to do. >> > >> > Any help appreciated. >> > >> >> >> |
|||||||||||||||||||||||