Showing posts with label RadAsyncUpload. Show all posts
Showing posts with label RadAsyncUpload. Show all posts

Wednesday, March 30, 2016

RadAsyncUpload upload files using ftp Protocol for Large Files Example using c#

this example upload files using ftp protocol using radasync Upload.

.aspx page


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="UploadToFtpSample.aspx.cs" Inherits="UploadToFtpSample" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        <telerik:RadScriptManager ID="RadScriptManager1" runat="server"></telerik:RadScriptManager>
        <div>
            <telerik:RadAsyncUpload ID="RadAsyncUpload1" runat="server" OnFileUploaded="RadAsyncUpload1_FileUploaded"></telerik:RadAsyncUpload>
            <asp:Button ID="Button1" Text="Upload" runat="server" />
       
        </div>
    </form>
</body>
</html>




Code Page.
using System;
using Telerik.Web.UI;
using System.Net;

public partial class UploadToFtpSample : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void RadAsyncUpload1_FileUploaded(object sender, Telerik.Web.UI.FileUploadedEventArgs e)
    {
        string ftp = "ftp://serverip:ftpPort/";
        string username = "xxxxx";
        string password = "xxxxxx";

        UploadToFtp(e.File, ftp, username, password);
    }

    public void UploadToFtp(UploadedFile file, string url, string username, string password)
    {
        var request = (FtpWebRequest)WebRequest.Create(new Uri(url + file.FileName));
        request.Timeout = 10000000;
        request.ReadWriteTimeout = 10000000;
        request.Method = WebRequestMethods.Ftp.UploadFile;
     
        request.KeepAlive = false;
        request.Credentials = new NetworkCredential(username, password);
        request.ContentLength = file.ContentLength;
     

        var requestStream = request.GetRequestStream();
        byte[] bytes = new byte[file.InputStream.Length];
        file.InputStream.Read(bytes, 0, bytes.Length);

        requestStream.Write(bytes, 0, (int)file.ContentLength);
        requestStream.Close();

        var response = (FtpWebResponse)request.GetResponse();

        if (response != null)
            response.Close();
    }

}


web.config Configuration
<httpRuntime executionTimeout="100000" maxRequestLength="2147483647" useFullyQualifiedRedirectUrl="false" minFreeThreads="8" minLocalRequestFreeThreads="4" appRequestQueueLimit="100" enableVersionHeader="true"/>




Ftp Server Configuration