Here I am giving the code to access ftp server thruogh your .net applcation. The code works on both windows as well as web. You can upload a file through ftp and make your own ftp client by researching more on this top.
System.Net.FtpWebRequest ftpClient=System.Net.FtpWebRequest.Create("ftp://Yoursite.com/yourdirectory/"+"Filename");
        ftpClient.Credentials = new System.Net.NetworkCredential("loginname", "password");
        ftpClient.Method=System.Net.WebRequestMethods.Ftp.UploadFile;
        ftpClient.UseBinary=true;
        System.IO.FileInfo fi= new System.IO.FileInfo("Local FilePath to be Uploaded");
        ftpClient.ContentLength=fi.Length;        
        int bufferSize=2048;
        byte[] content= new byte[bufferSize-1];
        int dataread;
        System.IO.FileStream fs=fi.OpenRead();
        try
        {
        }
        catch (Exception ex)
        {
            System.IO.Stream rs=ftpClient.GetRequestStream();
            do{
                dataread=fs.Read(content,0,bufferSize);
                rs.Write(content,0,dataread);
            }while(dataread<bufferSize);
        }
        finally
        {
            fs.Close();


0 comments:
Post a Comment