Can I read a text file that resides on another DASP site?

Discussion in 'Classic ASP' started by blueprintpm, Jul 29, 2010.

Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.
  1. I want to be able to read a file from within one of my pages - the file is in a folder on a different site that is also hosted by DASP.
    Is this possible? If so, can someone please post sample code for it? I use VB.net.
     
  2. Note: I have found code for FTP to another site to grab a folder, but I keep getting error 530 - not logged in. See the code here:
    'Values to use

    Const localFile As String = "C:\look.com"

    Const remoteFile As String = "/GPC/test_user_file.csv"

    Const host As String = "ftp://ftp.testsite.web110.discountasp.net/"

    Const username As String = "username"

    Const password As String = "pwd"



    'Create a request

    Dim URI As String = host & remoteFile

    Dim ftp As System.Net.FtpWebRequest = CType(System.Net.FtpWebRequest.Create(URI), System.Net.FtpWebRequest)

    'Set the credentials

    ftp.Credentials = New System.Net.NetworkCredential(username, password)

    'Turn off KeepAlive (will close connection on completion)

    ftp.KeepAlive = False

    'we want a binary

    ftp.UseBinary = True

    'Define the action required (in this case, download a file)

    ftp.Method = System.Net.WebRequestMethods.Ftp.DownloadFile



    'If we were using a method that uploads data e.g. UploadFile

    'we would open the ftp.GetRequestStream here an send the data



    'Get the response to the Ftp request and the associated stream

    '******* THIS NEXT LINE GETS THE 530-Not logged In error!

    Using response As System.Net.FtpWebResponse = CType(ftp.GetResponse, System.Net.FtpWebResponse)

    Using responseStream As IO.Stream = response.GetResponseStream

    'loop to read & write to file

    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
     
  3. Hey! It works! Good stuff. I had the wrong password (duh). I have about 12 DASP sites and I had mixed up the passwords :(
     
  4. mjp

    mjp

    Good deal, glad it's working for you.
     
Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.

Share This Page