Click here to Skip to main content
15,895,799 members
Articles / Programming Languages / C#

An FTP secure client library for C#

Rate me:
Please Sign up or sign in to vote.
4.61/5 (34 votes)
10 Dec 2008CPOL2 min read 495.1K   15.8K   135  
How to implement an FTP secure connection with an SSL stream class.
using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.Net.Sockets;
using System.Security.Permissions;

using FTP_DLL.Properties;

namespace FTP_DLL
{
    class Program
    {

        static void Main(string[] args)
        {
            try
            {


                FTPFactory ftp = new FTPFactory();

                ftp.setDebug(true);
                ftp.setRemoteHost(Settings.Default.TargetFtpSource);

                //Connect to SSL Port (990)
                ftp.setRemotePort(990);
                ftp.loginWithoutUser();

                string cmd = "AUTH SSL";
                ftp.sendCommand(cmd);

                //Create SSL Stream
                ftp.getSslStream();
                ftp.setUseStream(true);


                //Login  FTP Secure
                ftp.setRemoteUser(Settings.Default.TargetFtpSecureUser);
                ftp.setRemotePass(Settings.Default.TargetFtpSecurePass);
                ftp.login();

                //Set ASCII Mode
                ftp.setBinaryMode(false);


                //Upload file

                // Send Argument if you want
                //cmd = "site arg1 arg2";
                //ftp.sendCommand(cmd);

                ftp.upload("", false);
                ftp.uploadSecure(@"Filepath", false);


                ftp.close();





            }
            catch (Exception e)
            {
                Console.WriteLine("Caught Error :" + e.Message);
            }

        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect
Belgium Belgium
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions