This project is read-only.

AUTH SSL/TLS Exception - Build 2179

Apr 26, 2011 at 7:41 PM

Howdy!

I'm writing a little discovery code to become familiar with System.Net.FtpClient and am running into an exception fairly early on.

I am testing against an outside FTPS server an encountering an exception telling me that the AUTH SSL/TLS is missing before the login attempt.
I have verified that this is definitely not being transmitted with a packet capture.

It is very possible that I am completely missing something.. but I did follow along your example and the other bug report's code and I think
I have everything.

Let me know what you think..

public
void listFiles(string hostName, string user, string pw) { using (FtpClient cl = new FtpClient() { Username = user, Password = pw, Server = hostName}) { cl.Connect(); cl.SetWorkingDirectory("/"); FtpListItem[] listing = cl.GetListing(); foreach (FtpListItem item in listing) { Console.WriteLine(item); } } }

 

 

System.Net.FtpClient.FtpException was unhandled
  Message=Invalid sequence of commands (AUTH SSL/TLS required prior to authentication).
  Source=System.Net.FtpClient
  StackTrace:
       at System.Net.FtpClient.FtpClient.Login()
       at System.Net.FtpClient.FtpChannelConnected.Invoke()
       at System.Net.FtpClient.FtpChannel.OnConnectionReady()
       at System.Net.FtpClient.FtpChannel.Connect(String host, Int32 port)
       at System.Net.FtpClient.FtpChannel.Connect()
       at ConsoleApplications.ftp_job.listFiles(String hostName, String user, String pw) in C:\Users\dcalef\My Dropbox\programs\Visual Studio 2010\Projects\ConsoleApplications\ConsoleApplications\ftp-job.cs:line 22
       at ConsoleApplications.Program.Main(String[] args) in C:\Users\dcalef\My Dropbox\programs\Visual Studio 2010\Projects\ConsoleApplications\ConsoleApplications\Program.cs:line 23
       at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException:

Apr 26, 2011 at 7:47 PM

Do you mind sending the transaction log from the output window of your IDE? All versions of Visual Studio and I think SharpDevelop have this feature. When you start the program from within the IDE, the Debug.WriteLine() output is sent to the Output window in the IDE. This information will help to debug the problem.

 

No login credentials are supposed to be sent until after SSL/TLS has been setup. It could be that the server you're connecting to requires implicit SSL (connecting directly to an FTPS port) which this code does not yet support. The current code only support explicit SSL meaning after the initial connection, a secure channel is negotiated with the server.

Apr 26, 2011 at 7:56 PM

I believe I have all available debugging turned on here..

'ConsoleApplications.exe': Loaded 'C:\Users\dcalef\My Dropbox\programs\Visual Studio 2010\Projects\ConsoleApplications\ConsoleApplications\bin\Debug\ConsoleApplications.exe', No native symbols in symbol file.
'ConsoleApplications.exe': Loaded 'C:\Windows\System32\ntdll.dll', Cannot find or open the PDB file
'ConsoleApplications.exe': Loaded 'C:\Windows\System32\mscoree.dll', Cannot find or open the PDB file
'ConsoleApplications.exe': Loaded 'C:\Windows\System32\kernel32.dll', Cannot find or open the PDB file
'ConsoleApplications.exe': Loaded 'C:\Windows\System32\KernelBase.dll', Cannot find or open the PDB file
'ConsoleApplications.exe': Loaded 'C:\Windows\System32\apphelp.dll', Cannot find or open the PDB file
'ConsoleApplications.exe': Loaded 'C:\Windows\AppPatch\AcGenral.dll', Cannot find or open the PDB file
'ConsoleApplications.exe': Loaded 'C:\Windows\System32\sechost.dll', Cannot find or open the PDB file
'ConsoleApplications.exe': Loaded 'C:\Windows\System32\msvcrt.dll', Cannot find or open the PDB file
'ConsoleApplications.exe': Loaded 'C:\Windows\System32\rpcrt4.dll', Cannot find or open the PDB file
'ConsoleApplications.exe': Loaded 'C:\Windows\System32\sspicli.dll', Cannot find or open the PDB file
'ConsoleApplications.exe': Loaded 'C:\Windows\System32\shlwapi.dll', Cannot find or open the PDB file
'ConsoleApplications.exe': Loaded 'C:\Windows\System32\gdi32.dll', Cannot find or open the PDB file
'ConsoleApplications.exe': Loaded 'C:\Windows\System32\user32.dll', Cannot find or open the PDB file
'ConsoleApplications.exe': Loaded 'C:\Windows\System32\lpk.dll', Cannot find or open the PDB file
'ConsoleApplications.exe': Loaded 'C:\Windows\System32\usp10.dll', Cannot find or open the PDB file
'ConsoleApplications.exe': Loaded 'C:\Windows\System32\uxtheme.dll', Cannot find or open the PDB file
'ConsoleApplications.exe': Loaded 'C:\Windows\System32\winmm.dll', Cannot find or open the PDB file
'ConsoleApplications.exe': Loaded 'C:\Windows\System32\samcli.dll', Cannot find or open the PDB file
'ConsoleApplications.exe': Loaded 'C:\Windows\System32\ole32.dll', Cannot find or open the PDB file
'ConsoleApplications.exe': Loaded 'C:\Windows\System32\oleaut32.dll', Cannot find or open the PDB file
'ConsoleApplications.exe': Loaded 'C:\Windows\System32\msacm32.dll', Cannot find or open the PDB file
'ConsoleApplications.exe': Loaded 'C:\Windows\System32\advapi32.dll', Cannot find or open the PDB file
'ConsoleApplications.exe': Loaded 'C:\Windows\System32\version.dll', Cannot find or open the PDB file
'ConsoleApplications.exe': Loaded 'C:\Windows\System32\shell32.dll', Cannot find or open the PDB file
'ConsoleApplications.exe': Loaded 'C:\Windows\System32\sfc.dll', Cannot find or open the PDB file
'ConsoleApplications.exe': Loaded 'C:\Windows\System32\sfc_os.dll', Cannot find or open the PDB file
'ConsoleApplications.exe': Loaded 'C:\Windows\System32\userenv.dll', Cannot find or open the PDB file
'ConsoleApplications.exe': Loaded 'C:\Windows\System32\profapi.dll', Cannot find or open the PDB file
'ConsoleApplications.exe': Loaded 'C:\Windows\System32\dwmapi.dll', Cannot find or open the PDB file
'ConsoleApplications.exe': Loaded 'C:\Windows\System32\setupapi.dll', Cannot find or open the PDB file
'ConsoleApplications.exe': Loaded 'C:\Windows\System32\cfgmgr32.dll', Cannot find or open the PDB file
'ConsoleApplications.exe': Loaded 'C:\Windows\System32\devobj.dll', Cannot find or open the PDB file
'ConsoleApplications.exe': Loaded 'C:\Windows\System32\urlmon.dll', Cannot find or open the PDB file
'ConsoleApplications.exe': Loaded 'C:\Windows\System32\wininet.dll', Cannot find or open the PDB file
'ConsoleApplications.exe': Loaded 'C:\Windows\System32\iertutil.dll', Cannot find or open the PDB file
'ConsoleApplications.exe': Loaded 'C:\Windows\System32\crypt32.dll', Cannot find or open the PDB file
'ConsoleApplications.exe': Loaded 'C:\Windows\System32\msasn1.dll', Cannot find or open the PDB file
'ConsoleApplications.exe': Loaded 'C:\Windows\System32\mpr.dll', Cannot find or open the PDB file
'ConsoleApplications.exe': Loaded 'C:\Windows\System32\imm32.dll', Cannot find or open the PDB file
'ConsoleApplications.exe': Loaded 'C:\Windows\System32\msctf.dll', Cannot find or open the PDB file
'ConsoleApplications.exe': Loaded 'C:\Windows\Microsoft.NET\Framework\v4.0.30319\mscoreei.dll', Cannot find or open the PDB file
'ConsoleApplications.exe': Loaded 'C:\Windows\Microsoft.NET\Framework\v2.0.50727\mscorwks.dll', Cannot find or open the PDB file
'ConsoleApplications.exe': Loaded 'C:\Windows\winsxs\x86_microsoft.vc80.crt_1fc8b3b9a1e18e3b_8.0.50727.4927_none_d08a205e442db5b5\msvcr80.dll', Cannot find or open the PDB file
'ConsoleApplications.exe': Loaded 'C:\Windows\Microsoft.NET\Framework\v2.0.50727\Culture.dll', Cannot find or open the PDB file
'ConsoleApplications.exe': Unloaded 'C:\Windows\Microsoft.NET\Framework\v2.0.50727\Culture.dll'
'ConsoleApplications.exe': Loaded 'C:\Windows\assembly\NativeImages_v2.0.50727_32\mscorlib\ebdaeaeb9f66c9035b5f11431f10cda4\mscorlib.ni.dll', Cannot find or open the PDB file
'ConsoleApplications.exe' (Managed (v2.0.50727)): Loaded 'C:\Windows\assembly\GAC_32\mscorlib\2.0.0.0__b77a5c561934e089\mscorlib.dll'
'ConsoleApplications.exe': Loaded 'C:\Windows\System32\cryptbase.dll', Cannot find or open the PDB file
'ConsoleApplications.exe' (Managed (v2.0.50727)): Loaded 'C:\Users\dcalef\My Dropbox\programs\Visual Studio 2010\Projects\ConsoleApplications\ConsoleApplications\bin\Debug\ConsoleApplications.exe', Symbols loaded.
'ConsoleApplications.exe': Loaded 'C:\Windows\Microsoft.NET\Framework\v2.0.50727\mscorjit.dll', Cannot find or open the PDB file
'ConsoleApplications.exe': Loaded 'ImageAtBase0x73a20000', Loading disabled by Include/Exclude setting.
'ConsoleApplications.exe': Loaded 'ImageAtBase0x840000', Loading disabled by Include/Exclude setting.
'ConsoleApplications.exe': Unloaded 'ImageAtBase0x73a20000'
'ConsoleApplications.exe': Loaded 'C:\Users\dcalef\My Dropbox\programs\Visual Studio 2010\Projects\ConsoleApplications\ConsoleApplications\bin\Debug\System.Net.FtpClient.dll', No native symbols in symbol file.
'ConsoleApplications.exe' (Managed (v2.0.50727)): Loaded 'C:\Users\dcalef\My Dropbox\programs\Visual Studio 2010\Projects\ConsoleApplications\ConsoleApplications\bin\Debug\System.Net.FtpClient.dll', Symbols loaded.
'ConsoleApplications.exe': Loaded 'C:\Windows\assembly\NativeImages_v2.0.50727_32\System\50c67f851ae3df2d0ab7d86fd1c5c7e0\System.ni.dll', Cannot find or open the PDB file
'ConsoleApplications.exe' (Managed (v2.0.50727)): Loaded 'C:\Windows\assembly\GAC_MSIL\System\2.0.0.0__b77a5c561934e089\System.dll'
'ConsoleApplications.exe': Loaded 'C:\Windows\assembly\NativeImages_v2.0.50727_32\System.Configuration\9d054fc9618b81d5703af1662cd11135\System.Configuration.ni.dll', Cannot find or open the PDB file
'ConsoleApplications.exe' (Managed (v2.0.50727)): Loaded 'C:\Windows\assembly\GAC_MSIL\System.Configuration\2.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll'
'ConsoleApplications.exe': Loaded 'C:\Windows\assembly\NativeImages_v2.0.50727_32\System.Xml\3e2e26902d69c9b707a87da975acb9b6\System.Xml.ni.dll', Cannot find or open the PDB file
'ConsoleApplications.exe' (Managed (v2.0.50727)): Loaded 'C:\Windows\assembly\GAC_MSIL\System.Xml\2.0.0.0__b77a5c561934e089\System.Xml.dll'
'ConsoleApplications.exe': Loaded 'C:\Windows\System32\ws2_32.dll', Cannot find or open the PDB file
'ConsoleApplications.exe': Loaded 'C:\Windows\System32\nsi.dll', Cannot find or open the PDB file
'ConsoleApplications.exe': Loaded 'C:\Windows\System32\mswsock.dll', Cannot find or open the PDB file
'ConsoleApplications.exe': Loaded 'C:\Windows\System32\WSHTCPIP.DLL', Cannot find or open the PDB file
'ConsoleApplications.exe': Loaded 'C:\Windows\System32\wship6.dll', Cannot find or open the PDB file
'ConsoleApplications.exe': Loaded 'C:\Windows\System32\dnsapi.dll', Cannot find or open the PDB file
'ConsoleApplications.exe': Loaded 'C:\Windows\System32\IPHLPAPI.DLL', Cannot find or open the PDB file
'ConsoleApplications.exe': Loaded 'C:\Windows\System32\winnsi.dll', Cannot find or open the PDB file
'ConsoleApplications.exe': Loaded 'C:\Windows\System32\rasadhlp.dll', Cannot find or open the PDB file
'ConsoleApplications.exe': Loaded 'C:\Windows\System32\FWPUCLNT.DLL', Cannot find or open the PDB file
A first chance exception of type 'System.Net.FtpClient.FtpException' occurred in System.Net.FtpClient.dll
An unhandled exception of type 'System.Net.FtpClient.FtpException' occurred in System.Net.FtpClient.dll

Additional information: Invalid sequence of commands (AUTH SSL/TLS required prior to authentication).

The thread 'Win32 Thread' (0x1fe4) has exited with code 0 (0x0).
The thread 'Win32 Thread' (0xb80) has exited with code 0 (0x0).
The thread 'Win32 Thread' (0x1328) has exited with code 0 (0x0).
The thread 'Win32 Thread' (0x1af0) has exited with code 0 (0x0).
The program '[5348] ConsoleApplications.exe: Native' has exited with code 0 (0x0).
The program '[5348] ConsoleApplications.exe: Managed (v2.0.50727)' has exited with code 0 (0x0).

Apr 26, 2011 at 8:29 PM

It could be that the server you're connecting to requires implicit SSL (connecting directly to an FTPS port) which this code does not yet support. The current code only support explicit SSL meaning after the initial connection, a secure channel is negotiated with the server.

 

I think that is what is going on here. I stood up a quick Filezilla server and can see the AUTH TLS / SSL take place.

 

Thanks for your help! I will watch for when this is implemented.

 

 

Apr 26, 2011 at 8:31 PM

I'm working on it now, shouldn't be too long. Will post back here when it's ready.

Apr 26, 2011 at 9:00 PM

Revision 2488 supports implicit ssl now, here's an example:

using (FtpClient ftp = new FtpClient() { Server = "localhost", Username = "test", Password = "test", DefaultDataMode = FtpDataMode.Active, SslMode = FtpSslMode.Implicit, Port = 990 }) {
	ftp.InvalidCertificate += new FtpInvalidCertificate(cl_InvalidCertificate);

	FtpListItem[] items = ftp.GetListing();
	foreach (FtpListItem item in items)
		Console.WriteLine("{0} {1}", item.Name, item.Type.ToString());
}

Please make note that this example uses port 990 (the default SSL port for FTP) and not 21. The port number is not automatically changed when changing SSL modes.

Let me know how this works out, lightly tested on my end with FileZilla.

Apr 27, 2011 at 2:40 PM

Cool! I will take a look momentarily.

Apr 27, 2011 at 7:17 PM

Where does "cl_InvalidCertificate" get defined and populated?

Apr 27, 2011 at 7:56 PM

It's the event handler that is called when a certificate fails verification. The method can be found here:

http://netftp.codeplex.com/SourceControl/changeset/view/2492#22372

Apr 28, 2011 at 1:59 PM

That did the trick. Everything is looking good now. Excellent work!