Showing posts with label file. Show all posts
Showing posts with label file. Show all posts

Friday, March 21, 2014

File uploading using FTP in C#

Sometimes we need to upload files into a directory of a different website from our site, even just yesterday I found this kind of problem. My actual site is in its own server, I wanted to upload files from another server(admin panel). So for that I found this way very useful. And now I am sharing my code with you.

On a button click, get the FileUploader to get the file name and the user-name, password of the ftp server.

Now write the following code into the Button_Click event.

Upload("ftp://ftpserver.com", "user-name", "password", "<Your file name from FileUploader>");

And in the Upload method write down the code.

private static void Upload(string ftpServer, string userName, string password, string filename)
{
   using (System.Net.WebClient client = new System.Net.WebClient())
   {
      client.Credentials = new System.Net.NetworkCredential(userName, password);
      client.UploadFile(ftpServer + "/" + new FileInfo(filename).Name, "STOR", filename);
   }
}


If your website does not have a ftp server then open the parallel plux and create a ftp server with user-name and password, and then try to upload the files.

For more ftp upload info you can visit the MSDN website of Microsoft.


Ref : http://madskristensen.net/post/simple-ftp-file-upload-in-c-20

Tuesday, March 4, 2014

File uploading in ASP.NET using C# with file checking

File uploading is an important thing for any kind of websites, and in this post I will show you how to upload a file from your website to server using C#.

For this you need to add a control called FileUploder and a button. So take a web form and add a file uploader control with a button. For uploading files you need to use a method named  FileUpload.SaveAs. Here using this method upload the file into the desire path in the server.

Popular Posts

Pageviews