Sign In/My Account | View Cart  

advertisement

AddThis Social Bookmark Button

Article:
  Building FTP Services Using .NET 2.0
Subject:   Building FTP Services
Date:   2009-02-02 07:32:41
From:   DeeInSimsbury
This appears to be what I want, but I need it in C#. Has anyone converted successfull to C#. Im not very good with converting from VB to C#.
Full Threads Oldest First

Showing messages 1 through 1 of 1.

  • Building FTP Services
    2009-11-18 06:54:47  tapsa_gbg [View]

    string username = "*****";
    string password = "*****";
    //string domain = "****";

    string filename = @"C:\test\HelloWorld.txt";
    string address = "ftp://****";

    try
    {
    FtpWebRequest ftpReq = (FtpWebRequest)WebRequest.Create(address);
    ftpReq.Method = WebRequestMethods.Ftp.UploadFile;
    ftpReq.Credentials = new NetworkCredential(username, password);
    StreamReader stream = new StreamReader(filename);
    byte[] b = System.Text.Encoding.UTF8.GetBytes(stream.ReadToEnd());
    stream.Close();

    ftpReq.ContentLength = b.Length;
    Stream s = ftpReq.GetRequestStream();
    s.Write(b, 0, b.Length);
    s.Close();

    FtpWebResponse ftpResp = (FtpWebResponse)ftpReq.GetResponse();
    Console.WriteLine(ftpResp.StatusDescription);
    }
    catch (Exception ex)
    {
    Console.WriteLine(String.Format("ftpwebrequest: {0}, {1}", DateTime.Now.ToString(), ex.Message));
    }
    Console.ReadLine();