Topic "Connection failed error on Server 2012R2 (C# code)"

Author Message
ted1122
[View user's profile]

Joined: 2014-04-07
Posts: 2
Location: Australia
Hi,

I have recently wrote a simple C# code that connects to our FTP server and download files using WinSCP library.
Everything works great in our local dev machine but when I move it to the server, the code start throwing exception when opening a new connection.

The exception is as follows:

Connection failed.
at WinSCP.SessionLogReader.Read(LogReadFlags flags)
at WinSCP.ElementLogReader.Read(LogReadFlags flags)
at WinSCP.CustomLogReader.TryWaitForNonEmptyElement(String localName, LogReadFlags flags)
at WinSCP.Session.Open(SessionOptions sessionOptions)


The server is running Windows Server 2012R2 (a virtual machine on Hyper V)
WinSCP version is 5.52 (dll and standalone .exe)

The code is very similar to the example code at https://winscp.net/eng/docs/library_session_getfiles#example
Heres the code snippet that I used to initiate a session:
Code:
private Session _session = null;

public FTPSession()
{
    if (_session == null)
    {
        _session = new Session();
        _session.ExecutablePath = Settings.WINSCP_EXE;
        _session.Open(Options);               
    }
}

private SessionOptions Options
{
    get
    {
        return new SessionOptions
        {
            Protocol = Protocol.Ftp,
            HostName = Settings.FTP_Host, //read from config file
            UserName = Settings.FTP_UserName, //read from config file
            Password = Settings.FTP_Password, //read from config file
            Timeout = TimeSpan.FromSeconds(Settings.FTP_TimeOut), //read from config file
            FtpSecure = (Settings.FTP_SSL) ? FtpSecure.ExplicitSsl : FtpSecure.None //read from config file
        };
    }
}


I could connect to the FTP server successfully through GUI (on the server). I tried to add exception to the FireWall, raise account permissions etc but all didnt work...
Is there anything else that might have caused this issue?
Much appreciated with the help!!
Advertisements
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 25015
Location: Prague, Czechia
Please attach a full session log file showing the problem (using the latest version of WinSCP). Log from successful GUI session would be helpful too.

To generate log file, set Session.SessionLogPath. Submit the log with your post as an attachment. Note that passwords and passphrases not stored in the log. You may want to remove other data you consider sensitive though, such as host names, IP addresses, account names or file names (unless they are relevant to the problem). If you do not want to post the log publicly, you may email it to me. You will find my address (if you log in) in my forum profile. Please include link back to this topic in your email. Also note in this topic that you have emailed the log.

_________________
Martin Prikryl
ted1122
[View user's profile]

Joined: 2014-04-07
Posts: 2
Location: Australia
Please find attached session log.
It turned out to be a confirmation about certificate was encountered and then failed.

When connected through GUI or from my desktop, this confirmation doesnt appear. (the GUI log doesnt say much other than the session name and time)

Thanks!
session_log.txt (4.25 KB) [Download]

Description: (none)

martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 25015
Location: Prague, Czechia
Please read documentation:
https://winscp.net/eng/docs/scripting#hostkey

If that does not help, come back.
_________________
Martin Prikryl
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