PDA

View Full Version : VB .NET upload



cozo
02-28-2008, 10:02 PM
Hi,

Trying to use a .NET 2.0 application to upload some files to the bluehost server.

using the following line (its only one line in the code)

networkinstance.UploadFile("C:\Documents and Settings\pecoster\Desktop\ALPS REPORTER 2008\bin\Rocket.pdf", "http://www.mydomain.com/onlinealps/1/template.csv")

if the template.csv file exists alreadythis doesnt give any errors or warnings but it doesnt upload the file either..

If the file does not exist then it gives a 404 error.

I suspected that this wouldnt work without passwords and login but what password etc should I use?

Is it possible at all?

Thanks

felgall
02-28-2008, 10:26 PM
Where are you running .net? Bluehost doesn't support it.

lazynitwit
03-01-2008, 03:24 PM
The UploadFile function sends the file to a script (as POST data), not directly to the server. As such you need to provide a script as the URL that will handle the uploads.

A very basic example of one in PHP would be:

<?php
// Set this to the path where you want the files to be saved
// (include the trailing slash)
// ex: /home/username/public_html/upload/
$upload_dir = '/home/username/public_html/upload/';
if (isset($_FILES['file'])) {
// we are uploading a file.
$filename = $upload_dir . basename($_FILES['file']['name']);
move_uploaded_file($_FILES['file']['tmp_name'], $filename);
}
?>

Pass the path to the script as the URL to upload to. I don't recommend using this script, especially without putting it in a password-protected directory.

Note: This isn't a way I could recommend uploading files, you'd be better off using FTP (which I believe Net.WebClient supports, UploadFile might too)