public override Directory GetDirectory(string path) { _client.SetCurrentDirectory(path); string gcd = _client.GetCurrentDirectory(); return(new Directory(gcd.Substring(gcd.LastIndexOf("/")), gcd, null, null)); }
public void ConnectTest() { using (FTPSClient client = new FTPSClient()) { // Connect to the server, with mandatory SSL/TLS // encryption during authentication and // optional encryption on the data channel // (directory lists, file transfers) try { // client.Connect("us1.DOMAIN.com", new NetworkCredential(read-write, password), ESSLSupportMode.CredentialsRequired | ESSLSupportMode.DataChannelRequested); // client.Connect("us1.DOMAIN.com", new NetworkCredential(read-write, password), ESSLSupportMode.CredentialsRequired | ESSLSupportMode.DataChannelRequested); // client.Connect("us1.DOMAIN.com", new NetworkCredential(read-write, password), ESSLSupportMode.ControlAndDataChannelsRequired); // client.Connect("ftp.DOMAIN.com", new NetworkCredential(read-write, password), ESSLSupportMode.ClearText); client.Connect("ftps.DOMAIN.com", new NetworkCredential("username", password), ESSLSupportMode.ControlAndDataChannelsRequested); // client.MakeDir(System.Guid.NewGuid().ToString()); var sys = client.GetSystem(); var current = client.GetCurrentDirectory(); // client.SetCurrentDirectory("/Directory"); // client.GetFile("/Directory/File.ext", "c:\\temp\\File.ext"); } catch (Exception ex) { // handle exception } finally { client.Close(); } } }
/// <summary> /// Return the working directory /// </summary> /// <returns></returns> public string WorkingDirectory() { try { return(_client.GetCurrentDirectory()); } catch (IOException) { Disconnect(); ViewModel.Instance.IsConnected = false; } return(null); }
private static void DoList(FTPSClient client) { string remoteDirName = null; if (commandArguments.Count > 0) { remoteDirName = NormalizeRemotePath(commandArguments[0]); } else { remoteDirName = client.GetCurrentDirectory(); } Console.WriteLine(); Console.WriteLine("Remote directory: " + remoteDirName); // Get the dirList before the WriteLine in order to avoid writing an empty newline in case of exceptions string dirList = client.GetDirectoryListUnparsed(remoteDirName); Console.WriteLine(); Console.WriteLine(dirList); }
private static void DoList(FTPSClient client) { string remoteDirName = null; if (commandArguments.Count > 0) remoteDirName = NormalizeRemotePath(commandArguments[0]); else remoteDirName = client.GetCurrentDirectory(); Console.WriteLine(); Console.WriteLine("Remote directory: " + remoteDirName); // Get the dirList before the WriteLine in order to avoid writing an empty newline in case of exceptions string dirList = client.GetDirectoryListUnparsed(remoteDirName); Console.WriteLine(); Console.WriteLine(dirList); }
internal static long GetLatestSaleNo() { string Host = null; Int32 Port = 0; string Username = null; string Password = null; DateTime Latest = Convert.ToDateTime("1/1/1970"); Host = "192.168.44.40"; Username = "******"; Password = "******"; Port = 990; long saleNo = 0; Console.WriteLine("Opening ftp connection"); // Download the XML transcript and pop it into AMS... using (FTPSClient client = new FTPSClient()) { try { client.Connect(Host, Port, new NetworkCredential(Username, Password), ESSLSupportMode.CredentialsRequired | ESSLSupportMode.DataChannelRequested | ESSLSupportMode.Implicit, new System.Net.Security.RemoteCertificateValidationCallback(AcceptAllCertifications), new System.Security.Cryptography.X509Certificates.X509Certificate(), 0, 0, 0, 60000, true); LogMsg("GetLatestSaleNo - FTP Connected "); Console.WriteLine("FTP connected"); } catch (FTPCommandException fe) { LogMsg(fe); return(0); } catch (IOException ie) { LogMsg(ie); return(0); } catch (SocketException ie) { LogMsg(ie); return(0); } try { // Change to Transaction log directory String pwd = client.GetCurrentDirectory(); client.SetCurrentDirectory("TransactionLogs"); } catch (FTPCommandException fe) { LogMsg(fe); return(0); } try { { Console.WriteLine("Find latest file"); // Find latest file List <DirectoryListItem> ftpItems = client.GetDirectoryList().ToList(); string lastFile = ""; // Find latest file foreach (DirectoryListItem FtpItem in ftpItems) { if (FtpItem.Name.CompareTo(lastFile) > 0) { lastFile = FtpItem.Name; } } Console.WriteLine("GetLatestSaleNo " + lastFile); if (lastFile != null) { saleNo = Convert.ToInt64(lastFile.Substring(0, 4)); } LogMsg("GetLatestSaleNo " + saleNo); Console.WriteLine("GetLatestSaleNo " + saleNo); } return(saleNo); //return (4800); } catch (FTPCommandException fe) { LogMsg(fe); return(0); } catch (IOException ie) { LogMsg(ie); return(0); } catch (IndexOutOfRangeException ie) { LogMsg(ie); return(0); } } }
public static string GetXMLFile(int saleid) { string Host = null; Int32 Port = 0; string Username = null; string Password = null; string thisone = ""; DateTime Latest = Convert.ToDateTime("1/1/1970"); // Get FTP credentials from config // Auction.AuctionConfig config = Administration.ReadConfigFile(); // LogMsg("GetXMLFile"); try { // Ftp Server settings /* Host = config.FtpServer; * Username = config.FtpUser; * Password = Auction.DecodeFrom64(config.FtpPassword); * Port = Int32.Parse(config.FtpPort);*/ // Host = "54.154.210.120"; Host = "192.168.44.40"; Username = "******"; Password = "******"; Port = 990; } catch (ArgumentNullException ne) { LogMsg(ne); return(""); } catch (FormatException fe) { LogMsg(fe); return(""); } string targetDirectory = "C:\\TransactionLogs"; ulong?largest = 0; // Download the XML transcript and pop it into AMS... using (FTPSClient client = new FTPSClient()) { try { client.Connect(Host, Port, new NetworkCredential(Username, Password), ESSLSupportMode.CredentialsRequired | ESSLSupportMode.DataChannelRequested | ESSLSupportMode.Implicit, new System.Net.Security.RemoteCertificateValidationCallback(AcceptAllCertifications), new System.Security.Cryptography.X509Certificates.X509Certificate(), 0, 0, 0, 60000, true); LogMsg("GetXMLFile - FTP Connected to sale " + saleid); } catch (FTPCommandException fe) { LogMsg(fe); return(""); } catch (IOException ie) { LogMsg(ie); return(""); } catch (SocketException ie) { LogMsg(ie); return(""); } try { // Change to Transaction log directory String pwd = client.GetCurrentDirectory(); client.SetCurrentDirectory("TransactionLogs"); } catch (FTPCommandException fe) { LogMsg(fe); return(""); } try { string directory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), @"Humboldt\AuctionController\transactionlogs\"); directory = "C:\\TransactionLogs\\"; // Make sure directory exists if (Directory.Exists(directory)) { } else { Directory.CreateDirectory(directory); } { // Find latest file List <DirectoryListItem> ftpItems = client.GetDirectoryList().ToList(); LogMsg("GetXMLFile - Current Sale"); largest = 0; foreach (DirectoryListItem FtpItem in ftpItems) { if (FtpItem.Name.IndexOf(saleid.ToString()) == 0) { ulong?size = client.GetFileTransferSize(FtpItem.Name); if (size > largest) { thisone = FtpItem.Name; largest = size; } } } } LogMsg("GetXMLFile - getting " + thisone + " into " + directory + thisone); if (thisone.Length > 0) { client.GetFile(thisone, directory + thisone); } return(directory + thisone); } catch (FTPCommandException fe) { LogMsg(fe); return(""); } catch (IOException ie) { LogMsg(ie); return(""); } catch (IndexOutOfRangeException ie) { LogMsg(ie); return(""); } } }