FTP file upload in .NET 2.0

Posted By Venu Thomas

It is clear that the FileUpload components, which can be found on the Standard toolbar of Visual Studio 2005 allows uploading files to the remote site, but does not cover all the expectations desired or at least not mine.
So it is interesting to know how we can attack a specific server and an FTP to copy the desired file to the remote location to stay.

To do this:

Step 1: In general declarations establish that the class will use.

C#

using System.Net;

VB.NET

Imports System.Net

Step 2: Create a button in the Click event and write the following code in C# or VB.NET:

C#

private static void wc_UploadFTP(string ftpServerPath, string filename, string username, string password)
 {
WebClient ClientFtp = new WebClient() ;
ClientFtp.Credentials = new NetworkCredential(username, password);
ClientFtp.UploadFile(ftpServerPath + "/" + new FileInfo(filename).Name, "STOR", filename);
}

VB.NET


Private Shared Sub wc_UploadFTP(ByVal ftpServerPath As String, ByVal filename As String, ByVal username As String, ByVal password As String)
 Dim ClientFtp As New WebClient()
 ClientFtp.Credentials = New NetworkCredential(username, password)
 ClientFtp.UploadFile((ftpServerPath & "/") + New FileInfo(filename).Name, "STOR", filename)
End Sub

Happy Programming!!

Tags: , , ,

  •  
  • Share with others:

    Thanks for visiting us! If you enjoyed these icons please feel free to share them! Or if you want to know what's going on with WiseCodes.com, follow us!

    Leave a Reply

    Anti-Spam Protection by WP-SpamFree

    Locations of visitors to this page eXTReMe Tracker