0

I have following code:

var listDirectoryFtpRequest = (FtpWebRequest) WebRequest.Create(directoryUri);
listDirectoryFtpRequest.Method = WebRequestMethods.Ftp.ListDirectory;
listDirectoryFtpRequest.Credentials = /* my credentials */;
listDirectoryFtpRequest.KeepAlive = false;
listDirectoryFtpRequest.UsePassive = true;
listDirectoryFtpRequest.UseBinary = true;

using (var response = listDirectoryFtpRequest.GetResponse())
{
    return true;
}

The directory, which is stored in directoryUri, does exist.

I have following log from my ftp-server

(022102) 30.05.2012 08:32:18 - **USER** (213.235.245.89)> 230 Logged on
(022102) 30.05.2012 08:32:19 - **USER** (213.235.245.89)> OPTS utf8 on
(022102) 30.05.2012 08:32:19 - **USER** (213.235.245.89)> 200 UTF8 mode enabled
(022102) 30.05.2012 08:32:20 - **USER** (213.235.245.89)> PWD
(022102) 30.05.2012 08:32:20 - **USER** (213.235.245.89)> 257 "/" is current directory.
(022102) 30.05.2012 08:32:21 - **USER** (213.235.245.89)> CWD /21792543/2/
(022102) 30.05.2012 08:32:21 - **USER** (213.235.245.89)> 250 CWD successful. "/21792543/2" is current directory.
(022102) 30.05.2012 08:32:22 - **USER** (213.235.245.89)> TYPE I
(022102) 30.05.2012 08:32:22 - **USER** (213.235.245.89)> 200 Type set to I
(022102) 30.05.2012 08:32:23 - **USER** (213.235.245.89)> PASV
(022102) 30.05.2012 08:32:23 - **USER** (213.235.245.89)> 227 Entering Passive Mode (10,40,31,10,229,112)
(022102) 30.05.2012 08:32:27 - **USER** (213.235.245.89)> NLST
(022102) 30.05.2012 08:32:27 - **USER** (213.235.245.89)> 150 Connection accepted
(022102) 30.05.2012 08:32:27 - **USER** (213.235.245.89)> 226 Transfer OK
(022102) 30.05.2012 08:32:29 - **USER** (213.235.245.89)> disconnected.

Nevertheless I get following exception:

System.Net.WebException: The underlying connection was closed: The server committed a protocol violation.
   at System.Net.FtpWebRequest.SyncRequestCallback(Object obj)
   at System.Net.FtpWebRequest.RequestCallback(Object obj)
   at System.Net.CommandStream.InvokeRequestCallback(Object obj)
   at System.Net.CommandStream.Abort(Exception e)
   at System.Net.FtpWebRequest.FinishRequestStage(RequestStage stage)
   at System.Net.FtpWebRequest.GetResponse()
   at **MYCLASS**.**MYMETHOD**

Why? ... and how can I fix this?

PS.: I've found another question here on SO with similar symptoms. But do I really have to go for the KeepAlive = true-hack?

Community
  • 1
  • 1

1 Answers1

0

Oh my dear ... The .Net-implementation is not fixed until 3.5 - maybe it is by 4.0 ... Anyway: I used System.Net.FtpClient to fix my uploading/downloading/requesting ...

  • I'm having this same problem too. There are a few .NET FTP providers but was System.Net.FtpClient the only one that resolved the error? The project is still in beta so I'm hesitant to use it. – HBCondo Oct 22 '12 at 07:12
  • System.Net.FtpClient was/is the only ftp-client which was easy to use (nice and handy interface) and does a lot of things under the hood (eg. multi-level-dir checks) which you'd have to implement yourself ... was a bit frightened by beta-status, but we are actually using this in an enterprise-environment, and yes, it works like charm! –  Oct 22 '12 at 08:01