Still getting error on Fingerprint but partner not using

Advertisement

Philky001
Donor
Joined:
Posts:
20

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.

// 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;

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
40,476
Location:
Prague, Czechia

Re: Still getting error on Fingerprint but partner not using

But the current partner does NOT want or have the finger print.
That does not make sense. Every SSH server has a host key. And a fingerprint is just computed from that host key (what means that every SSH server "has a fingerprint").

Did you read this?
https://winscp.net/eng/docs/faq_hostkey
https://winscp.net/eng/docs/message_sessionoptions_sshhostkeyfingerprint_is_not_set

Reply with quote

Advertisement

You can post new topics in this forum