public static void TestFTPAccount(FTPAccount account, bool silent) { string msg; string sfp = account.GetSubFolderPath(); using (FTP ftpClient = new FTP(account)) { try { DateTime time = DateTime.Now; ftpClient.Test(sfp); msg = "Success!"; } catch (Exception e) { if (e.Message.StartsWith("Could not change working directory to")) { try { ftpClient.MakeMultiDirectory(sfp); ftpClient.Test(sfp); msg = "Success!\nAuto created folders: " + sfp; } catch (Exception e2) { msg = e2.Message; } } else { msg = e.Message; } } } if (!string.IsNullOrEmpty(msg)) { string ping = SendPing(account.Host, 3); if (!string.IsNullOrEmpty(ping)) { msg += "\n\nPing results:\n" + ping; } if (silent) { FileSystem.AppendDebug(string.Format("Tested {0} sub-folder path in {1}", sfp, account.ToString())); } else { MessageBox.Show(msg, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information); } } }
public static void TestFTPAccount(FTPAccount account, bool silent) { string msg = string.Empty; string sfp = account.GetSubFolderPath(); bool succ = false; switch (account.Protocol) { case FTPProtocol.SFTP: SFTP sftp = new SFTP(account); if (!sftp.IsInstantiated) { msg = "An SFTP client couldn't be instantiated, not enough information.\nCould be a missing key file."; } else { sftp.Connect(); List <string> createddirs = new List <string>(); if (!sftp.DirectoryExists(sfp)) { createddirs = sftp.CreateMultipleDirectorys(FTPHelpers.GetPaths(sfp)); } if (sftp.IsConnected) { msg = (createddirs.Count == 0) ? "Connected!" : "Conected!\nCreated folders;\n"; for (int x = 0; x <= createddirs.Count - 1; x++) { msg += createddirs[x] + "\n"; } msg += " \n\nPing results:\n " + SendPing(account.Host, 3); sftp.Disconnect(); } } break; default: using (FTP ftpClient = new FTP(account)) { try { succ = ftpClient.Test(sfp); if (succ) { msg = "Success!"; } } catch (Exception e) { if (e.Message.StartsWith("Could not change working directory to")) { try { ftpClient.MakeMultiDirectory(sfp); ftpClient.Test(sfp); msg = "Success!\nAuto created folders: " + sfp; } catch (Exception e2) { msg = e2.Message; } } else { msg = e.Message; } } } if (succ && !string.IsNullOrEmpty(msg)) { string ping = SendPing(account.Host, 3); if (!string.IsNullOrEmpty(ping)) { msg += "\n\nPing results:\n" + ping; } } break; } if (succ && silent) { DebugHelper.WriteLine(string.Format("Tested {0} sub-folder path in {1}", sfp, account.ToString())); } else if (succ) { MessageBox.Show(msg, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information); } }