473,803 Members | 4,591 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

Feb 7 '07 #1
2 3011
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(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
Feb 8 '07 #2
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
3572
by: Kevin Spencer | last post by:
Hi all, I am working on a service that uploads METAR weather information to the National Weather Service FTP site. The service I'm authoring is hosted on a Windows 200 server, and the NWS FTP host is on a Unix server. I'm using the FtpWebRequest and FtpWebResponse classes to do the file uploading. I have tested it without any errors at all uploading to an IIS FTP server hosted on our network Most of the time it uploads without error to...
7
16222
by: jose.lopes.cruz | last post by:
I need to access a FTP Server. I'm using FTPWebRequest as described in visual studio 2005 documentation. Everything works fine except the following: 1) I dont know how to change de current working directory on the server to the parent directory? 2) Why cant I do this, or why doesn't work? In Internet explorer works! <some code...for FtpWebRequest>
0
2773
by: Alexis | last post by:
Hello, I am trying to upload a file to an ftp server using the FtpWebRequest class, but I get the following error. The requested URI is invalid for this FTP command. I do can upload the file from the Internet Explorer so I have rights to do it. Why is the 2.0 FtpWebRequest class failing? What I am doing wrong? My Code:
0
9803
by: Buddy Home | last post by:
Hello, I'm trying to upload a file programatically and occasionally I get the following error message. Unable to write data to the transport connection: An established connection was aborted by the software in your host machine. Stack Trace at System.Net.Sockets.NetworkStream.Write(Byte buffer, Int32 offset, Int32
6
9462
by: William LaMartin | last post by:
Could someone show me how to use the FtpWebRequest and change to a different directory? Changing directories is not listed as one of the methods, but I believe it can be done--just can't figure out how.
5
7695
by: Sendil kumar | last post by:
Hi All, The FtpWebRequest.GetResponse( ) method is not giving "550 File not found exception " when I do a directory list operation on a invalid(not present) directory in HP Unix and Sun Solaris system, but the same is working fine in windows. For example, this is my uri to connect to the Sun Solaris server machine "ftp://ssriniva:ssriniva@apfsun/apfqa/users/ssriniva/apfhome/config" here the 'config' folder is not present in the...
0
1299
by: jason7069 | last post by:
Hi There. I recently implemented a FTP upload feature within an ASP.NET application. I use the standard steps that are posted throughout the web. The basic funcationality works as a file is created on the FTP server that is the identical size to what I am uploaded. However, if the file is a non-text format (JPG, XLS) the resulting file that is posted to FTP is not a valid file type. For example, I uploaded a JPG and
9
3903
by: Waldy | last post by:
Hi there, I have written a service in VS2005 that downloads files from an FTP site processes them and then deletes the files if successfully processed. It all works fine when run in our test lab with an FTP site that I setup on IIS. However, I have an issue at the customer site. Their FTP server is on Linux, but I presume that is not an issue. What happened the first time I ran it was that it deleted every other file. It just so...
6
13694
by: Patrick.Simons | last post by:
I try to connect a FTPWebRequest through Proxy and VPN to a remote FTP- server. Sometimes it works sometimes not. When my VB.Net-App (2005) returns the error on the GetResponse-Method, I'll try to use the Windows Explorer to go on the FTP-URI and this always works. So the problem should come from my app. my simplified code: Private m_oFTP As FtpWebRequest Private oResponseDir As FtpWebResponse = Nothing
0
10548
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10316
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10069
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9125
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7604
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6842
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5500
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5629
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3798
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.