Topic "Still getting error on Fingerprint but partner not using"

Author Message
Philky001
[View user's profile]
Donor
Joined: 2015-11-24
Posts: 20
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.

Code:
// 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:

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;
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24552
Location: Prague, Czechia
Quote:
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?
http://winscp.net/eng/docs/faq_hostkey
Advertisements

You can post new topics in this forum






Search Site

What is WinSCP?

It is award-winning SFTP client, SCP client, FTPS client and FTP client integrated into one software program for file transfer to FTP server or secure SFTP server. [More]

And it's free!

Donate

About donations

$9   $19   $49   $99

About donations

Recommend

WinSCP Privacy Policy

WinSCP License