Still getting error on Fingerprint but partner not using
I am getting an error and need to change codes.
The issue is I am reusing code from partner that has the SSH fingerprint. But the current partner does NOT want or have the finger print.
So I comment out that. but still getting error.
ERROR LOG:
Error:System.ArgumentException: SessionOptions.Protocol is Protocol.Sftp or Protocol.Scp, but SessionOptions.SshHostKeyFingerprint is not set.
at WinSCP.Session.SessionOptionsToOpenSwitches(SessionOptions sessionOptions)
at WinSCP.Session.SessionOptionsToOpenCommand(SessionOptions sessionOptions, String& command, String& log)
at WinSCP.Session.Open(SessionOptions sessionOptions)
at SFTPGetConsoleVersionPOSI.PosiFileSftp.PutPosiFile() in \\fs1\userdata\philk\My Documents\SFTP_POSI\SFTPGetConsoleVersionPOSI\SFTPGetConsoleVersionPOSI\PosiFileSftp.cs:line 122 - 2/25/2016 3:50:27 PM
-------Program End---------- - 2/25/2016 3:50:27 PM
-------Program Ends ---------- - 2/25/2016 3:50:27 PM
Rest of code:
The issue is I am reusing code from partner that has the SSH fingerprint. But the current partner does NOT want or have the finger print.
So I comment out that. but still getting error.
// Setup session options SessionOptions sessionOptions = new SessionOptions { Protocol = Protocol.Sftp, HostName = ConfigurationManager.AppSettings["HostName"].ToString(), UserName = ConfigurationManager.AppSettings["UserName"].ToString(), Password = ConfigurationManager.AppSettings["Password"].ToString(), //SshHostKeyFingerprint = ConfigurationManager.AppSettings["SshHostKeyFingerprint"].ToString() };
ERROR LOG:
Error:System.ArgumentException: SessionOptions.Protocol is Protocol.Sftp or Protocol.Scp, but SessionOptions.SshHostKeyFingerprint is not set.
at WinSCP.Session.SessionOptionsToOpenSwitches(SessionOptions sessionOptions)
at WinSCP.Session.SessionOptionsToOpenCommand(SessionOptions sessionOptions, String& command, String& log)
at WinSCP.Session.Open(SessionOptions sessionOptions)
at SFTPGetConsoleVersionPOSI.PosiFileSftp.PutPosiFile() in \\fs1\userdata\philk\My Documents\SFTP_POSI\SFTPGetConsoleVersionPOSI\SFTPGetConsoleVersionPOSI\PosiFileSftp.cs:line 122 - 2/25/2016 3:50:27 PM
-------Program End---------- - 2/25/2016 3:50:27 PM
-------Program Ends ---------- - 2/25/2016 3:50:27 PM
Rest of code:
using (Session session = new Session()) { // Connect session.Open(sessionOptions); Helper.AddtoLogFile("-------Session instance successfully Created.----------"); // Upload files TransferOptions transferOptions = new TransferOptions(); transferOptions.TransferMode = TransferMode.Binary; transferOptions.PreserveTimestamp = false; List<SFTPmap> ImportFilePaths = DBProvider.Instance.DownloadParameters(); Helper.AddtoLogFile("All File Paths are downloaded."); foreach (SFTPmap item in ImportFilePaths) { if (!string.IsNullOrEmpty(item.FolderNameAlias) && !string.IsNullOrEmpty(item.FilePathPOSI) && !string.IsNullOrEmpty(item.FolderNamePOSI)) { try { var ToUpload = item.FolderNamePOSI; TransferOperationResult transferResult; if (!ToUpload.EndsWith("\\")) { ToUpload += "\\"; } var remotePath = item.FilePathPOSI; RemoteDirectoryInfo directory = null; Console.WriteLine("path", item.FilePathPOSI); List<string> filePaths = Directory.GetFiles(ToUpload).ToList(); foreach (string file in filePaths) { //if (directory.Files.Where(f => f.Name == Path.GetFileName(file)).Count()>0) //{ try { var curRemoteFileName = string.Format("{0}/", item.FilePathPOSI); transferResult = session.PutFiles(file, curRemoteFileName, false, transferOptions); // Throw on any error transferResult.Check(); // Print results foreach (TransferEventArgs transfer in transferResult.Transfers) { Console.WriteLine("Upload of {0} succeeded", transfer.FileName); Helper.AddtoLogFile("Upload of " + transfer.FileName + " succeeded"); Helper.AddtoLogFile("Seesion Log Path :" + session.SessionLogPath); } } catch (Exception ex) { Helper.AddtoLogFile("Error:" + ex.ToString()); Helper.AddtoLogFile("Seesion Log Path :" + session.SessionLogPath); } try { if (!string.IsNullOrEmpty(item.FolderNamePosiArchive)) { //Cut File From Source To destination string ArchiveFile = item.FolderNamePosiArchive; if (!ArchiveFile.EndsWith("\\")) { ArchiveFile += "\\"; } string filename = Path.GetFileName(file); ArchiveFile += filename; System.IO.File.Move(file, ArchiveFile); Console.WriteLine("File Moves from " + file + " to " + ArchiveFile); Helper.AddtoLogFile("File Moves from " + file + " to " + ArchiveFile); } } catch (Exception ex) { Helper.AddtoLogFile("Error:" + ex.ToString()); } //} } } catch (Exception ex) { Helper.AddtoLogFile("Error:" + ex.ToString()); } } } } Helper.AddtoLogFile("-------Program End----------"); return 0;