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

probls with file upload script... pls help

P: n/a
hi.

i am having probs understanding how to grab a file being uploaded from
a remote client. i am using hidden input fields for upload such as:

<input id="my_file_element" type="file" name="file_1" size=46 /><input
type=submit />

so, after adding a few files, the input fields look like this:

<input name="file_3" type="file"><input style="position: absolute;
left: -1000px;" name="file_2" type="file"><input style="position:
absolute; left: -1000px;" name="file_1" type="file"><input
style="position: absolute; left: -1000px;" id="my_file_element"
name="file_0" size="46" type="file"><input type="submit">

I am using the microsoft-provided clsFTP class for uploading files to
my server. below is the code that calls the class and attempts to
upload the user-added files...

Dim ftpClient As New Code.clsFTP("192.168.10.10", "", "anonymous",
Context.User.Identity.Name, 20)

If (ftpClient.Login() = True) Then

'Create a new folder
ftpClient.CreateDirectory("FTPFOLDERNEW")

'Set our new folder as our active directory
ftpClient.ChangeDirectory("FTPFOLDERNEW")

'Set FTP mode
ftpClient.SetBinaryMode(True)

// TEST HERE WITH FILE_1 - ALWAYS FAILS
dim params as String = Request.Params.Get("file_1")

'Upload a file from your local hard disk to the FTP site.
ftpClient.UploadFile(Server.MapPath(params))

ftpClient.CloseConnection()

End If

OK. the problem is that when Request.Params.Get("file_1") is called, it
gets the string path
of the file. so, ftpClientUploadFile looks for that string in the local
directory, be it Server.MapPath or simply ftpClient.UploadFile(params).
Since this file is coming from the *user's computer* and not my Web
Server, how do i do this?

eagerly awaiting responses...

Dec 9 '06 #1
Share this Question
Share on Google+
7 Replies


P: n/a
First thing, avoid using the Params collection. It's a performance hit since
it looks at the querystring, form, servervariables, and cookies collections.
It's always best to refer to the collection you want directly. Are you
FTPing the files to a server different than the one the web page is on? If
not, then you don't need FTP. You need to have a form handler of some sort
behind the input type="file". Grabbing the value isn't going to get you
anything other than the file name. ASP.Net 2.0 has a FileUpload component
built in. This will generate the appropriate html in the form of the input
file box, plus it will give you access to the file itself for download when
the user posts back to the server through something like a typical ASP.Net
button-click event. You can then call the FileUpload component's SaveAs
method to save the file somewhere directly, or you can use the Stream
property to get at the raw filestream to do something different with it
(such as attach the raw stream to an email as an email attachment).

Also, I don't know if the IP address you're using is simply for testing, but
keep in mind that the IP address 192.x.x.x is a non-routable address.
Basically that means nobody outside your immediate network (ie: behind your
router) will be able to find it since it's not meant to be accessed by the
outside.
--

Hope this helps,
Mark Fitzpatrick
Former Microsoft FrontPage MVP 199?-2006


"pbd22" <du*****@gmail.comwrote in message
news:11*********************@80g2000cwy.googlegrou ps.com...
hi.

i am having probs understanding how to grab a file being uploaded from
a remote client. i am using hidden input fields for upload such as:

<input id="my_file_element" type="file" name="file_1" size=46 /><input
type=submit />

so, after adding a few files, the input fields look like this:

<input name="file_3" type="file"><input style="position: absolute;
left: -1000px;" name="file_2" type="file"><input style="position:
absolute; left: -1000px;" name="file_1" type="file"><input
style="position: absolute; left: -1000px;" id="my_file_element"
name="file_0" size="46" type="file"><input type="submit">

I am using the microsoft-provided clsFTP class for uploading files to
my server. below is the code that calls the class and attempts to
upload the user-added files...

Dim ftpClient As New Code.clsFTP("192.168.10.10", "", "anonymous",
Context.User.Identity.Name, 20)

If (ftpClient.Login() = True) Then

'Create a new folder
ftpClient.CreateDirectory("FTPFOLDERNEW")

'Set our new folder as our active directory
ftpClient.ChangeDirectory("FTPFOLDERNEW")

'Set FTP mode
ftpClient.SetBinaryMode(True)

// TEST HERE WITH FILE_1 - ALWAYS FAILS
dim params as String = Request.Params.Get("file_1")

'Upload a file from your local hard disk to the FTP site.
ftpClient.UploadFile(Server.MapPath(params))

ftpClient.CloseConnection()

End If

OK. the problem is that when Request.Params.Get("file_1") is called, it
gets the string path
of the file. so, ftpClientUploadFile looks for that string in the local
directory, be it Server.MapPath or simply ftpClient.UploadFile(params).
Since this file is coming from the *user's computer* and not my Web
Server, how do i do this?

eagerly awaiting responses...

Dec 9 '06 #2

P: n/a

thanks tons for your reply mark.

yes, the local IP addy is just for testing. And, i am FTPing to another

box on the network that is not the same box as the Web server.

i considered your suggestion about asp:fileupload but i decided to go
another route mostly because i want to avoid trips to the server if i
can. so,
i hunted down the below page which does everything on the client except
for the actual upload:

http://the-stickman.com/web-developm...-file-element/

i also liked the fact that this script allows the user to add as many
files as possible
via one input box (well, it looks that way, anyway. the additional ones
are added
as "hidden" dynamically).

so, if i am not going with the asp FileUpload utility, how do i grab
the file for FTP?
you are right that i am just getting the string version of the file,
and not the actual
file. how would this be done with a <input type=file?

thanks again for the help.

Dec 10 '06 #3

P: n/a
Forgive me if I'm misunderstanding you, but it sounds like you're using an
FTP client to upload a file to an HTTP web application. Can you be more
specific about the Work Flow of your app? Apparently, you have an ASP.Net
page that has a file upload element in it, and the file begins by uploading
a file via HTTP (your ASP.Net page) to your web server. What happens after
that? How is the uploaded file handled by your web application? Is your web
application attempting to transfer it to an FTP server, or what?

--
HTH,

Kevin Spencer
Microsoft MVP
Logostician
http://unclechutney.blogspot.com

There is a madness to my method.

"pbd22" <du*****@gmail.comwrote in message
news:11*********************@80g2000cwy.googlegrou ps.com...
hi.

i am having probs understanding how to grab a file being uploaded from
a remote client. i am using hidden input fields for upload such as:

<input id="my_file_element" type="file" name="file_1" size=46 /><input
type=submit />

so, after adding a few files, the input fields look like this:

<input name="file_3" type="file"><input style="position: absolute;
left: -1000px;" name="file_2" type="file"><input style="position:
absolute; left: -1000px;" name="file_1" type="file"><input
style="position: absolute; left: -1000px;" id="my_file_element"
name="file_0" size="46" type="file"><input type="submit">

I am using the microsoft-provided clsFTP class for uploading files to
my server. below is the code that calls the class and attempts to
upload the user-added files...

Dim ftpClient As New Code.clsFTP("192.168.10.10", "", "anonymous",
Context.User.Identity.Name, 20)

If (ftpClient.Login() = True) Then

'Create a new folder
ftpClient.CreateDirectory("FTPFOLDERNEW")

'Set our new folder as our active directory
ftpClient.ChangeDirectory("FTPFOLDERNEW")

'Set FTP mode
ftpClient.SetBinaryMode(True)

// TEST HERE WITH FILE_1 - ALWAYS FAILS
dim params as String = Request.Params.Get("file_1")

'Upload a file from your local hard disk to the FTP site.
ftpClient.UploadFile(Server.MapPath(params))

ftpClient.CloseConnection()

End If

OK. the problem is that when Request.Params.Get("file_1") is called, it
gets the string path
of the file. so, ftpClientUploadFile looks for that string in the local
directory, be it Server.MapPath or simply ftpClient.UploadFile(params).
Since this file is coming from the *user's computer* and not my Web
Server, how do i do this?

eagerly awaiting responses...

Dec 10 '06 #4

P: n/a

hi kevin,

well, its the other way around. i am using an HTTP Web application to
upload files to an FTP server. i am new to this so, corrections
welcome.
the user is on the Web server where he accesses the upload page.
he uses the form outlined in the Stickman link to upload multiple
files. .
once he hits "upload" on the upload page, the script is called that
logs
onto the FTP server and sends the file from the user's computer to the
FTP server (via the Web server).

i was thinking that this will cause havoc on the http traffic and that
the best
way to do it is to redirect the users to the FTP server (for the
presentation layer)
so the whole upload process is handled by the FTP server. is this the
way to go?

So:

1. User Logs On To Web Server (ASP.NET Pages)
2. User Accesses Upload Form On Web Server
3. User Uses Hiddend Inputs To Upload Multiple Files
4. User Hits Upoload_Click On Same Form
5. Upload_Click runs VB.NET script that calls clsFTP
6. clsFTP is a script that logs onto the FTP server (a different
computer) and,
if all goes well, sends the file(s).

here is a link to clsFTP:
http://www.dotnethero.com/hero/vbnet/ftp.aspx?nmx=8_4

thanks again,
peter

Kevin Spencer wrote:
Forgive me if I'm misunderstanding you, but it sounds like you're using an
FTP client to upload a file to an HTTP web application. Can you be more
specific about the Work Flow of your app? Apparently, you have an ASP.Net
page that has a file upload element in it, and the file begins by uploading
a file via HTTP (your ASP.Net page) to your web server. What happens after
that? How is the uploaded file handled by your web application? Is your web
application attempting to transfer it to an FTP server, or what?

--
HTH,

Kevin Spencer
Microsoft MVP
Logostician
http://unclechutney.blogspot.com

There is a madness to my method.

"pbd22" <du*****@gmail.comwrote in message
news:11*********************@80g2000cwy.googlegrou ps.com...
hi.

i am having probs understanding how to grab a file being uploaded from
a remote client. i am using hidden input fields for upload such as:

<input id="my_file_element" type="file" name="file_1" size=46 /><input
type=submit />

so, after adding a few files, the input fields look like this:

<input name="file_3" type="file"><input style="position: absolute;
left: -1000px;" name="file_2" type="file"><input style="position:
absolute; left: -1000px;" name="file_1" type="file"><input
style="position: absolute; left: -1000px;" id="my_file_element"
name="file_0" size="46" type="file"><input type="submit">

I am using the microsoft-provided clsFTP class for uploading files to
my server. below is the code that calls the class and attempts to
upload the user-added files...

Dim ftpClient As New Code.clsFTP("192.168.10.10", "", "anonymous",
Context.User.Identity.Name, 20)

If (ftpClient.Login() = True) Then

'Create a new folder
ftpClient.CreateDirectory("FTPFOLDERNEW")

'Set our new folder as our active directory
ftpClient.ChangeDirectory("FTPFOLDERNEW")

'Set FTP mode
ftpClient.SetBinaryMode(True)

// TEST HERE WITH FILE_1 - ALWAYS FAILS
dim params as String = Request.Params.Get("file_1")

'Upload a file from your local hard disk to the FTP site.
ftpClient.UploadFile(Server.MapPath(params))

ftpClient.CloseConnection()

End If

OK. the problem is that when Request.Params.Get("file_1") is called, it
gets the string path
of the file. so, ftpClientUploadFile looks for that string in the local
directory, be it Server.MapPath or simply ftpClient.UploadFile(params).
Since this file is coming from the *user's computer* and not my Web
Server, how do i do this?

eagerly awaiting responses...
Dec 10 '06 #5

P: n/a
ok,

i think i may be close. if you have read my previous post, apologies as
i think this
might be why i am having probs sending the actual file(s) to the
server. when my ASP.NET
page loads, it loads with the <formtag provided in the Site.master
page.

so, the page in question loads with this tag:

<form name="aspnetForm" method="post" action="upload.aspx"
id="aspnetForm">

but, per the online reading, i have to include a form tag on my page
that will call the server code and reference the enctype. hence:

<form name="uploadForm" id="uploadForm" action="data_upload.aspx"
enctype="multipart/form-data">

so, both of these tags appear on my upload page. i am guessing this is
causing some
confusion?

how do i change the form tag if it is required in the Site.master page?
thanks again.

Dec 11 '06 #6

P: n/a
Well, the concept is okay (having a user upload a file to your web
application, and then having the web application upload the files to the FTP
server), but you're missing the part where you get the file from the web
client. You need to use the Request.Files Collection to get the files. This
is because any HTML form for uploading files must have the enctype attribute
"multipart/form-data", and you can't read the files without it.

--
HTH,

Kevin Spencer
Microsoft MVP
Logostician
http://unclechutney.blogspot.com

There is a madness to my method.

"pbd22" <du*****@gmail.comwrote in message
news:11*********************@16g2000cwy.googlegrou ps.com...
>
hi kevin,

well, its the other way around. i am using an HTTP Web application to
upload files to an FTP server. i am new to this so, corrections
welcome.
the user is on the Web server where he accesses the upload page.
he uses the form outlined in the Stickman link to upload multiple
files. .
once he hits "upload" on the upload page, the script is called that
logs
onto the FTP server and sends the file from the user's computer to the
FTP server (via the Web server).

i was thinking that this will cause havoc on the http traffic and that
the best
way to do it is to redirect the users to the FTP server (for the
presentation layer)
so the whole upload process is handled by the FTP server. is this the
way to go?

So:

1. User Logs On To Web Server (ASP.NET Pages)
2. User Accesses Upload Form On Web Server
3. User Uses Hiddend Inputs To Upload Multiple Files
4. User Hits Upoload_Click On Same Form
5. Upload_Click runs VB.NET script that calls clsFTP
6. clsFTP is a script that logs onto the FTP server (a different
computer) and,
if all goes well, sends the file(s).

here is a link to clsFTP:
http://www.dotnethero.com/hero/vbnet/ftp.aspx?nmx=8_4

thanks again,
peter

Kevin Spencer wrote:
>Forgive me if I'm misunderstanding you, but it sounds like you're using
an
FTP client to upload a file to an HTTP web application. Can you be more
specific about the Work Flow of your app? Apparently, you have an ASP.Net
page that has a file upload element in it, and the file begins by
uploading
a file via HTTP (your ASP.Net page) to your web server. What happens
after
that? How is the uploaded file handled by your web application? Is your
web
application attempting to transfer it to an FTP server, or what?

--
HTH,

Kevin Spencer
Microsoft MVP
Logostician
http://unclechutney.blogspot.com

There is a madness to my method.

"pbd22" <du*****@gmail.comwrote in message
news:11*********************@80g2000cwy.googlegro ups.com...
hi.

i am having probs understanding how to grab a file being uploaded from
a remote client. i am using hidden input fields for upload such as:

<input id="my_file_element" type="file" name="file_1" size=46 /><input
type=submit />

so, after adding a few files, the input fields look like this:

<input name="file_3" type="file"><input style="position: absolute;
left: -1000px;" name="file_2" type="file"><input style="position:
absolute; left: -1000px;" name="file_1" type="file"><input
style="position: absolute; left: -1000px;" id="my_file_element"
name="file_0" size="46" type="file"><input type="submit">

I am using the microsoft-provided clsFTP class for uploading files to
my server. below is the code that calls the class and attempts to
upload the user-added files...

Dim ftpClient As New Code.clsFTP("192.168.10.10", "", "anonymous",
Context.User.Identity.Name, 20)

If (ftpClient.Login() = True) Then

'Create a new folder
ftpClient.CreateDirectory("FTPFOLDERNEW")

'Set our new folder as our active directory
ftpClient.ChangeDirectory("FTPFOLDERNEW")

'Set FTP mode
ftpClient.SetBinaryMode(True)

// TEST HERE WITH FILE_1 - ALWAYS FAILS
dim params as String = Request.Params.Get("file_1")

'Upload a file from your local hard disk to the FTP site.
ftpClient.UploadFile(Server.MapPath(params))

ftpClient.CloseConnection()

End If

OK. the problem is that when Request.Params.Get("file_1") is called, it
gets the string path
of the file. so, ftpClientUploadFile looks for that string in the local
directory, be it Server.MapPath or simply ftpClient.UploadFile(params).
Since this file is coming from the *user's computer* and not my Web
Server, how do i do this?

eagerly awaiting responses...

Dec 11 '06 #7

P: n/a
thanks again kevin.

ok, the problem can be boiled down to this one hurdle:

the compiler isnt seeing the uploadForm (multipart/form-data) form tag
inside the aspnetForm tag.

the following javascript function needs to call the uploadForm tag
surrounding the upload input elements:

function buildQueryString(theFormName) {
theForm = document.forms[0];
var qs = ''

for (e=0;e<theForm.elements.length;e++) {
alert(e);
if (theForm.elements[e].name!='') {
qs+=(qs=='')?'?':'&'

qs+=theForm.elements[e].name+'='+escape(theForm.elements[e].value)
}
}
alert(qs);
return qs

}

but, document.forms[0] calls the aspnetForm master page form tag, not
the upload form tag.
if i do document.forms[1], document.forms[2], document.forms[3] or
whatever, the compiler
can't find:

<form id="uploadForm" name="uploadForm" enctype="multipart/form-data"
method="post">

which is embedded inside of:

<form name="aspnetForm" method="post" action="upload.aspx"
id="aspnetForm">

i know i have been milking this question for all its worth, but i am
positive this is my prob. i'll keep at it in the mean time.

thanks again.

Kevin Spencer wrote:
Well, the concept is okay (having a user upload a file to your web
application, and then having the web application upload the files to the FTP
server), but you're missing the part where you get the file from the web
client. You need to use the Request.Files Collection to get the files. This
is because any HTML form for uploading files must have the enctype attribute
"multipart/form-data", and you can't read the files without it.

--
HTH,

Kevin Spencer
Microsoft MVP
Logostician
http://unclechutney.blogspot.com

There is a madness to my method.

"pbd22" <du*****@gmail.comwrote in message
news:11*********************@16g2000cwy.googlegrou ps.com...

hi kevin,

well, its the other way around. i am using an HTTP Web application to
upload files to an FTP server. i am new to this so, corrections
welcome.
the user is on the Web server where he accesses the upload page.
he uses the form outlined in the Stickman link to upload multiple
files. .
once he hits "upload" on the upload page, the script is called that
logs
onto the FTP server and sends the file from the user's computer to the
FTP server (via the Web server).

i was thinking that this will cause havoc on the http traffic and that
the best
way to do it is to redirect the users to the FTP server (for the
presentation layer)
so the whole upload process is handled by the FTP server. is this the
way to go?

So:

1. User Logs On To Web Server (ASP.NET Pages)
2. User Accesses Upload Form On Web Server
3. User Uses Hiddend Inputs To Upload Multiple Files
4. User Hits Upoload_Click On Same Form
5. Upload_Click runs VB.NET script that calls clsFTP
6. clsFTP is a script that logs onto the FTP server (a different
computer) and,
if all goes well, sends the file(s).

here is a link to clsFTP:
http://www.dotnethero.com/hero/vbnet/ftp.aspx?nmx=8_4

thanks again,
peter

Kevin Spencer wrote:
Forgive me if I'm misunderstanding you, but it sounds like you're using
an
FTP client to upload a file to an HTTP web application. Can you be more
specific about the Work Flow of your app? Apparently, you have an ASP.Net
page that has a file upload element in it, and the file begins by
uploading
a file via HTTP (your ASP.Net page) to your web server. What happens
after
that? How is the uploaded file handled by your web application? Is your
web
application attempting to transfer it to an FTP server, or what?

--
HTH,

Kevin Spencer
Microsoft MVP
Logostician
http://unclechutney.blogspot.com

There is a madness to my method.

"pbd22" <du*****@gmail.comwrote in message
news:11*********************@80g2000cwy.googlegrou ps.com...
hi.

i am having probs understanding how to grab a file being uploaded from
a remote client. i am using hidden input fields for upload such as:

<input id="my_file_element" type="file" name="file_1" size=46 /><input
type=submit />

so, after adding a few files, the input fields look like this:

<input name="file_3" type="file"><input style="position: absolute;
left: -1000px;" name="file_2" type="file"><input style="position:
absolute; left: -1000px;" name="file_1" type="file"><input
style="position: absolute; left: -1000px;" id="my_file_element"
name="file_0" size="46" type="file"><input type="submit">

I am using the microsoft-provided clsFTP class for uploading files to
my server. below is the code that calls the class and attempts to
upload the user-added files...

Dim ftpClient As New Code.clsFTP("192.168.10.10", "", "anonymous",
Context.User.Identity.Name, 20)

If (ftpClient.Login() = True) Then

'Create a new folder
ftpClient.CreateDirectory("FTPFOLDERNEW")

'Set our new folder as our active directory
ftpClient.ChangeDirectory("FTPFOLDERNEW")

'Set FTP mode
ftpClient.SetBinaryMode(True)

// TEST HERE WITH FILE_1 - ALWAYS FAILS
dim params as String = Request.Params.Get("file_1")

'Upload a file from your local hard disk to the FTP site.
ftpClient.UploadFile(Server.MapPath(params))

ftpClient.CloseConnection()

End If

OK. the problem is that when Request.Params.Get("file_1") is called, it
gets the string path
of the file. so, ftpClientUploadFile looks for that string in the local
directory, be it Server.MapPath or simply ftpClient.UploadFile(params).
Since this file is coming from the *user's computer* and not my Web
Server, how do i do this?

eagerly awaiting responses...
Dec 11 '06 #8

This discussion thread is closed

Replies have been disabled for this discussion.