By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,818 Members | 1,381 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,818 IT Pros & Developers. It's quick & easy.

FTPWebRequest File.ReadOpen Could Not Find File

P: n/a
Hello,

I am having trouble with the following code using ASP.Net 2.0. I
recieve an error on the line File.OpenRead(fPath) 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.Create(server & "/" &
filename)

'Call A FileUpload Method of FTP Request Object
reqObj.Method = WebRequestMethods.Ftp.UploadFile

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

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

'Store File in Buffer
Dim buffer(streamObj.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.GetRequestStream().Write(buffer, 0, buffer.Length)
reqObj.GetRequestStream.Write(buffer, 0, buffer.Length)
reqObj = Nothing

Feb 7 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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)

jl******@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(fPath) 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.Create(server & "/" &
filename)

'Call A FileUpload Method of FTP Request Object
reqObj.Method = WebRequestMethods.Ftp.UploadFile

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

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

'Store File in Buffer
Dim buffer(streamObj.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.GetRequestStream().Write(buffer, 0, buffer.Length)
reqObj.GetRequestStream.Write(buffer, 0, buffer.Length)
reqObj = Nothing
Feb 8 '07 #2

P: n/a
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

Feb 12 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.