Sunday, 12 August 2012

FTP server using Visual Basic .NET.

In this tutorial, we cover uploading files to an FTP server using Visual Basic .NET. Nowadays All are using ftp software to upload file their site, here a simple and easy code to upload file to your site using You can modify code that file path to give open file dialog box and many more complex make your own ftp. It’s easy copy hard to understand. First line of code give a site path where to upload and give user name and password and next line upload file, get file from computer and upload to server. Before start import Copy and paste below Code:
Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim request As System.Net.FtpWebRequest = DirectCast(System.Net.WebRequest.Create(""), System.Net.FtpWebRequest)
        request.Credentials = New System.Net.NetworkCredential("user", "password")
        request.Method = System.Net.WebRequestMethods.Ftp.UploadFile

        Dim file() As Byte = System.IO.File.ReadAllBytes("c:\file.txt")

        Dim strz As System.IO.Stream = request.GetRequestStream()
        strz.Write(file, 0, file.Length)
    End Sub

End Class
Real Time Web Analytics