[Mono-osx] FtpWebRequest "Not connected"

chromex loren.hoffman at gmail.com
Tue Feb 15 17:58:56 EST 2011


Hello,

I am porting a device management application from Windows to OSX and am
having problems with the FtpWebRequest system. I distilled an example of the
issue down to the code sample below. When run in OSX an exception is thrown
stating "Not connected". This is odd because if I put in the wrong
credentials then it gives the error: "Server returned an error: 530 Login
incorrect" which implies that it the "Not connected" error is happening
after a successful authentication. Besides this example being taken from
code that works in Windows it also correlates with all examples I have found
regarding FtpWebRequest. I have even checked that the final FtpWebRequest
fields match in Visual Studio and in Monodevelop right before the
GetResponse method is called; all do except for the Proxy property which
appears to be implemented slightly differently. Finally, I tried running the
code against multiple ftp servers including the target device and the built
in OSX ftp server, all with the same results. 

It is possible I have a simple issue I am overlooking or there is some
aspect of it that requires extra care in OSX. If anyone has any input on
this or can confirm the issue on other systems that would help a lot. If any
other information is needed outside what I have already provided please let
me know.

Cheers,
- Loren

/////
// Example

using System;
using System.Net;
using System.IO;

namespace TestFTP
{
	class MainClass
	{
		public static void Main (string[] args)
		{
			Console.WriteLine ("Starting test...");
			
			FtpWebRequest req = (FtpWebRequest)FtpWebRequest.Create(new
Uri("ftp://192.168.10.117/"));
			            
			req.Method = WebRequestMethods.Ftp.ListDirectoryDetails;
			req.UseBinary = false;
			req.KeepAlive = false;
			req.UsePassive = false;
			req.Credentials = new NetworkCredential("admin", "admin");
			try
			{
				FtpWebResponse response = (FtpWebResponse)req.GetResponse();
				StreamReader reader = new StreamReader(response.GetResponseStream());
				Console.WriteLine(reader.ReadToEnd());
				reader.Close();
			}
			catch(Exception e)
			{
				Console.WriteLine("Error: ");
				Console.WriteLine(e.Message);
			}
		}
	}
}

/////
// Run Output

cd "/Users/chromex/Projects/TestFTP/TestFTP/bin/Debug";
PKG_CONFIG_PATH="/Applications/MonoDevelop.app/Contents/MacOS/lib/pkgconfig:/Library/Frameworks/Mono.framework/Versions/2.6.7/share/pkgconfig:/Library/Frameworks/Mono.framework/Versions/2.6.7/lib/pkgconfig"
PKG_CONFIG_LIBDIR=""
PATH="/Library/Frameworks/Mono.framework/Versions/Current/bin:/usr/bin:/bin:/usr/sbin:/sbin"
/Library/Frameworks/Mono.framework/Versions/2.6.7/bin/mono --debug
"/Users/chromex/Projects/TestFTP/TestFTP/bin/Debug/TestFTP.exe" ; echo; read
-p 'Press any key to continue...' -n1; exit
Loren-Hoffmans-MacBook-Pro:~ chromex$ cd
"/Users/chromex/Projects/TestFTP/TestFTP/bin/Debug";
PKG_CONFIG_PATH="/Applications/MonoDevelop.app/Contents/MacOS/lib/pkgconfig:/Library/Frameworks/Mono.framework/Versions/2.6.7/share/pkgconfig:/Library/Frameworks/Mono.framework/Versions/2.6.7/lib/pkgconfig"
PKG_CONFIG_LIBDIR=""
PATH="/Library/Frameworks/Mono.framework/Versions/Current/bin:/usr/bin:/bin:/usr/sbin:/sbin"
/Library/Frameworks/Mono.framework/Versions/2.6.7/bin/mono --debug
"/Users/chromex/Projects/TestFTP/TestFTP/bin/Debug/TestFTP.exe" ; echo; read
-p 'Press any key to continue...' -n1; exit
Starting test...
Error: 
Not connected

-- 
View this message in context: http://mono.1490590.n4.nabble.com/FtpWebRequest-Not-connected-tp3307834p3307834.html
Sent from the Mono - OSX mailing list archive at Nabble.com.


More information about the Mono-osx mailing list