Click here to Skip to main content
12,252,903 members (58,232 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C#
I had used the following code but it executes with error msg texted on catch.source file exists on drive F and i have a folder named as New in C:/Wamp/www/New where i want to upload the file for test.the code is as...
private void upload_Click(object sender, EventArgs e)
{
Upload(@"F:/Rahul.txt");
label2.Text = "Uploading successfully completed...";
}
public void Upload(string fileToUpload)
{

try
{
FileInfo toUplaod = new FileInfo(fileToUpload);
FtpWebRequest request = (FtpWebRequest)WebRequest.Create("http://127.0.0.1/New/" + toUplaod.Name);
request.Method = WebRequestMethods.Ftp.UploadFile;
//request.Credentials = new NetworkCredential("USERNAME","PASSWORD");
Stream ftpstream = request.GetRequestStream();
FileStream file = File.OpenRead(fileToUpload);
int length = 1024;
byte[] buffer = new byte[length];
int bytesRead = 0;

do
{
bytesRead = file.Read(buffer, 0 ,length);
ftpstream.Write(buffer, 0, bytesRead);
}
while (bytesRead != 0);
file.Close();
ftpstream.Close();


}
catch
{
MessageBox.Show("Error ! connecting server..itni jaldi nhi chalunga Sir g..");
}



}
Thank you....
Posted 30-Dec-12 20:07pm
Edited 30-Dec-12 23:31pm
v2
Comments
   
Are you really running an HTTP server and service such a strange directory?
—SA
OriginalGriff 31-Dec-12 2:18am
   
This is not a good question - we cannot work out from that little what you are trying to do.
Remember that we can't see your screen, access your HDD, or read your mind.
Perhaps, if you take the comments out and tell us what problem you are getting it would help? At the moment all we have is a small chunk of simple code, and "It don't work" which is not helpful as errors messages go...
Use the "Improve question" widget to edit your question and provide better information.
@RahulTripathi17 31-Dec-12 5:34am
   
thank u sir to guide me ...if i use Webclient class to upload a file on server how should i code for that.

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

I cannot believe that not only you are running HTTP server on "http://localhost", on default port; and that your have a sub-directory named "/127.0.0.1". It's more likely that you do not quite understand the URI scheme; and you actual URL is "http://localhost/New".

Please see for more information: http://en.wikipedia.org/wiki/URI_scheme[^].

I also not quite sure that you are running any HTTP server at all. Did you install one? You never mentioned it, and I suspect you don't quite understand how it works. Sorry if I'm wrong about it.

Also, I want to note that there are no situations where using a hard-coded URL is useful. However, if this is just a preliminary test, it's probably OK.

—SA
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160426.1 | Last Updated 31 Dec 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100