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:
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!!