none
Reading a text file online without FTP RRS feed

  • Question

  • Hello,

    I've got a program running that uses basic templates to construct a text box in a text editor with different fonts and sizes, etc.

    I'm trying to get a text file online that the VB program can access and get information about more templates.

    Currently, I don't have the resources to set up an FTP client, so how could I host the text file online for the VB program to read?

    Thanks in advance.


    ---- JDS404 ---- Check out my blog at www.interlinkjds.wordpress.com!

    Saturday, June 23, 2018 5:10 PM

Answers

  • Currently, I don't have the resources to set up an FTP client, so how could I host the text file online for the VB program to read?

    Do you mean an FTP server?

    If the content is text in a web page then the client could access it using a browser and HTTP, which is supported by a number of applications..

    • Marked as answer by JDS404 Monday, June 25, 2018 9:05 AM
    Monday, June 25, 2018 12:56 AM
  • Are you trying to read the file on the FTP server and download it locally? If it is, you can use the following method(This does not require FTP Client):

    Sub getFileFromFTP(ByVal localFile As String, ByVal remoteFile As String, ByVal host As String, ByVal username As String, ByVal password As String)
            Dim URI As String = host & remoteFile
            Dim ftp As System.Net.FtpWebRequest = CType(FtpWebRequest.Create(URI), FtpWebRequest)
            ftp.Credentials = New System.Net.NetworkCredential(username, password)
            ftp.KeepAlive = False
            ftp.UseBinary = False
            ftp.Method = System.Net.WebRequestMethods.Ftp.DownloadFile
            Using response As System.Net.FtpWebResponse = CType(ftp.GetResponse, System.Net.FtpWebResponse)
                Using responseStream As IO.Stream = response.GetResponseStream
                    Using fs As New IO.FileStream(localFile, IO.FileMode.Create)
                        Dim buffer(2047) As Byte
                        Dim read As Integer = 0
                        Do
                            read = responseStream.Read(buffer, 0, buffer.Length)
                            fs.Write(buffer, 0, read)
                        Loop Until read = 0 'see Note(1)
                        responseStream.Close()
                        fs.Flush()
                        fs.Close()
                    End Using
                    responseStream.Close()
                End Using
                response.Close()
            End Using
        End Sub

    Best Regards

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by JDS404 Monday, June 25, 2018 9:05 AM
    Monday, June 25, 2018 9:01 AM

All replies

  • Please be specific. The following are too vague. And if you think I am being vague then at least you know how I feel.

    • a program
    • basic templates
    • a text editor
    • a text file
    • online
    • the VB program (where is it?)



    Sam Hobbs
    SimpleSamples.Info

    Sunday, June 24, 2018 11:50 PM
  • Currently, I don't have the resources to set up an FTP client, so how could I host the text file online for the VB program to read?

    Do you mean an FTP server?

    If the content is text in a web page then the client could access it using a browser and HTTP, which is supported by a number of applications..

    • Marked as answer by JDS404 Monday, June 25, 2018 9:05 AM
    Monday, June 25, 2018 12:56 AM
  • Are you trying to read the file on the FTP server and download it locally? If it is, you can use the following method(This does not require FTP Client):

    Sub getFileFromFTP(ByVal localFile As String, ByVal remoteFile As String, ByVal host As String, ByVal username As String, ByVal password As String)
            Dim URI As String = host & remoteFile
            Dim ftp As System.Net.FtpWebRequest = CType(FtpWebRequest.Create(URI), FtpWebRequest)
            ftp.Credentials = New System.Net.NetworkCredential(username, password)
            ftp.KeepAlive = False
            ftp.UseBinary = False
            ftp.Method = System.Net.WebRequestMethods.Ftp.DownloadFile
            Using response As System.Net.FtpWebResponse = CType(ftp.GetResponse, System.Net.FtpWebResponse)
                Using responseStream As IO.Stream = response.GetResponseStream
                    Using fs As New IO.FileStream(localFile, IO.FileMode.Create)
                        Dim buffer(2047) As Byte
                        Dim read As Integer = 0
                        Do
                            read = responseStream.Read(buffer, 0, buffer.Length)
                            fs.Write(buffer, 0, read)
                        Loop Until read = 0 'see Note(1)
                        responseStream.Close()
                        fs.Flush()
                        fs.Close()
                    End Using
                    responseStream.Close()
                End Using
                response.Close()
            End Using
        End Sub

    Best Regards

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by JDS404 Monday, June 25, 2018 9:05 AM
    Monday, June 25, 2018 9:01 AM