FTPWebRequest File.ReadOpen Could Not Find File

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • jlacefie@gmail.com

    FTPWebRequest File.ReadOpen Could Not Find File

    Hello,

    I am having trouble with the following code using ASP.Net 2.0. I
    recieve an error on the line File.OpenRead(f Path) stating could not
    find file . The fPath comes from a textbox control on the client and
    the error displays the correct path for the file. This code works
    when I use the browser on the server that is hosting the site, but it
    does not work when I access this site on any other machine. Does the
    OpenRead only work on local "server" files? I appreciated any help!

    'Create a FTP Request Object and Specfiy a Complete Path
    Dim reqObj As FtpWebRequest = WebRequest.Crea te(server & "/" &
    filename)

    'Call A FileUpload Method of FTP Request Object
    reqObj.Method = WebRequestMetho ds.Ftp.UploadFi le

    'If you want to access Resourse Protected You need to give
    User Name and PWD
    reqObj.Credenti als = New NetworkCredenti al(user, password)

    'FileStream object read file from Local Drive
    Dim streamObj As FileStream = File.OpenRead(f Path)

    'Store File in Buffer
    Dim buffer(streamOb j.Length) As Byte

    'Read File from Buffer
    streamObj.Read( buffer, 0, buffer.Length)

    'Close FileStream Object Set its Value to nothing
    streamObj.Close ()
    streamObj = Nothing

    'Upload File to ftp://localHost/ set its object to nothing
    'reqObj.GetRequ estStream().Wri te(buffer, 0, buffer.Length)
    reqObj.GetReque stStream.Write( buffer, 0, buffer.Length)
    reqObj = Nothing

  • bruce barker

    #2
    Re: FTPWebRequest File.ReadOpen Could Not Find File

    the ftp site requires credentials to open the file. to pass credentials
    to another server you need a primary security token. if the browser is
    local, you have one, else you have an impersonation token, which cannot
    be used for network access.

    options:

    1) have asp.net use a domain / account instead of impersonation.
    2) use basic authenication (givers server a primary token)
    3) use kerberos authenication with forwarding enabled

    -- bruce (sqlwork.com)

    jlacefie@gmail. com wrote:
    Hello,
    >
    I am having trouble with the following code using ASP.Net 2.0. I
    recieve an error on the line File.OpenRead(f Path) stating could not
    find file . The fPath comes from a textbox control on the client and
    the error displays the correct path for the file. This code works
    when I use the browser on the server that is hosting the site, but it
    does not work when I access this site on any other machine. Does the
    OpenRead only work on local "server" files? I appreciated any help!
    >
    'Create a FTP Request Object and Specfiy a Complete Path
    Dim reqObj As FtpWebRequest = WebRequest.Crea te(server & "/" &
    filename)
    >
    'Call A FileUpload Method of FTP Request Object
    reqObj.Method = WebRequestMetho ds.Ftp.UploadFi le
    >
    'If you want to access Resourse Protected You need to give
    User Name and PWD
    reqObj.Credenti als = New NetworkCredenti al(user, password)
    >
    'FileStream object read file from Local Drive
    Dim streamObj As FileStream = File.OpenRead(f Path)
    >
    'Store File in Buffer
    Dim buffer(streamOb j.Length) As Byte
    >
    'Read File from Buffer
    streamObj.Read( buffer, 0, buffer.Length)
    >
    'Close FileStream Object Set its Value to nothing
    streamObj.Close ()
    streamObj = Nothing
    >
    'Upload File to ftp://localHost/ set its object to nothing
    'reqObj.GetRequ estStream().Wri te(buffer, 0, buffer.Length)
    reqObj.GetReque stStream.Write( buffer, 0, buffer.Length)
    reqObj = Nothing
    >

    Comment

    • jlacefie@gmail.com

      #3
      Re: FTPWebRequest File.ReadOpen Could Not Find File

      Bruce,

      Thanks for the reply. Is it possible to implement your suggestions
      for authentication with a Forms Authentication site? Currently I am
      using Forms Authentication.

      Thanks,

      Jonathan

      Comment

      Working...