using System; using System.Collections; using System.IO; using System.Text; using System.Threading; using Jscape.Ftp; namespace FtpExample { public class FtpExample { public Ftp myFtp = null; public FtpExample() { myFtp = new Ftp("localhost","admin","admin"); myFtp.ConnectionType = Ftp.AUTH_TLS; //Ftp.IMPLICIT_SSL; myFtp.FtpConnectedEvent += new FtpConnectEventHandler(OnConnected); myFtp.FtpDisconnectedEvent += new FtpConnectEventHandler(OnDisconnected); myFtp.FtpCommandEvent += new FtpCommandEventHandler(OnCommand); myFtp.FtpResponseEvent +=new FtpCommandEventHandler(OnResponse); myFtp.FtpDownloadEvent +=new FtpDownloadEventHandler(OnDownload); myFtp.FtpUploadEvent +=new FtpDownloadEventHandler(OnUpload); myFtp.FtpProgressEvent +=new FtpProgressEventHandler(OnProgress); myFtp.FtpListingEvent +=new FtpListingEventHandler(OnListing); myFtp.FtpConnectionLostEvent +=new FtpConnectEventHandler(OnConnectionLost); myFtp.Connect(); IEnumerator e = myFtp.GetDirListing(); while (e.MoveNext()) { FtpFile file = (FtpFile)e.Current; Console.WriteLine("Filename: " + file.Filename); if (file.IsDirectory) { Console.WriteLine("\tDir Owner/Group: "+file.Owner + "/"+file.Group); }else if(file.Link) { Console.WriteLine("\tLink Target: "+file.LinkTarget); }else{ Console.WriteLine("\tFile Size: "+file.Size); Console.WriteLine("\tPermissions: "+file.Permission); Console.WriteLine("\tModify Date: "+file.Date); Console.WriteLine("\tModify Time: "+file.Time); } Console.WriteLine(); } // set remote dir myFtp.RemoteDir = "logs"; // download log files myFtp.MDownload("*.log"); //set remote dir myFtp.RemoteDir = "yoursite.com/images"); // upload all jpg images myFtp.MUpload("*.jpg"); myFtp.Disconnect(); } [STAThread] static void Main(string[] args) { FtpExample ftpExample = new FtpExample(); } private void OnConnected(object sender, FtpConnectEventArgs e) { Console.WriteLine("Ftp connected to " + e.HostName); } private void OnDisconnected(object sender, FtpConnectEventArgs e) { Console.WriteLine("Disconnected " + e.HostName); } } }