2009-10-22 12 views
5

Implementé mi clase FTP personalizada para trabajar con un servidor alojado por el que estoy pagando. Uso el FTP para realizar copias de seguridad, restaurar y actualizar mi aplicación. Ahora estoy en el momento en el que quiero permitir que el ssl ponga esto en producción. Le pregunté a mi empresa de hosting si soportan el protocolo SSL y me dijeron que sí.FtpWebRequest con EnableSSL

Así que modifica mis métodos después de Microsoft MSDN tutorial para algo como esto:

reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(m_ftpAddress.Trim())); 
reqFTP.UseBinary = true; 
reqFTP.Credentials = new NetworkCredential(m_ftpUsername, m_ftpPassword); 
reqFTP.Method = WebRequestMethods.Ftp.ListDirectory; 

ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(ValidateServerCertificate); 
       X509Certificate cert = new X509Certificate(path to a certificate created with makecert.exe); 

reqFTP.ClientCertificates.Add(cert); 
reqFTP.AuthenticationLevel = AuthenticationLevel.MutualAuthRequested; 
reqFTP.ImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Identification; 

reqFTP.EnableSsl = true; 

Ahora, el MSDN dice que si el servidor soporta el protocolo SSL no va a lanzar y una excepción cuando se le preguntó con Autenticación TLS. Esto se puede ver en el registro de seguimiento. Entonces supongo que no es un problema de servidor.

Después de la fase de autenticación del servidor devuelve un mensaje

System.Net Information: 0 : [0216] FtpControlStream#41622463 - Received response [227 Entering Passive Mode (the IP and port number).]

que desencadena un error:

System.Net Error: 0 : [0216] Exception in the FtpWebRequest#12547953::GetResponse - The remote server returned an error: 227 Entering Passive Mode (the IP and port number).

traté de establecer la propiedad

reqFTP.UsePassive = true; 

a falso y entonces consigo este error:

System.Net Information: 0 : [2692] FtpControlStream#4878312 - Received response [500 Illegal PORT command]

Por supuesto, sin la propiedad EnableSLL establecida en verdadero todo funciona sin problemas.

¿Alguien tiene alguna idea al respecto?

Editar: he modificado el código como barbechos:

reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(m_ftpAddress.Trim())); 
reqFTP.UseBinary = true; 
reqFTP.Credentials = new NetworkCredential(m_ftpUsername, m_ftpPassword); 
reqFTP.Method = WebRequestMethods.Ftp.ListDirectory; 

ServicePointManager.ServerCertificateValidationCallback = new  
    System.Net.Security.RemoteCertificateValidationCallback(ValidateServerCertificate); 

reqFTP.ClientCertificates.Add(cert); 
reqFTP.AuthenticationLevel = AuthenticationLevel.MutualAuthRequested; 
reqFTP.ImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Identification 
reqFTP.EnableSsl = true; 

El ValidateServerCertificate siempre devuelve verdadero . Después de estas modificaciones, el efecto es ninguno.

Y no entiendo:

  • En este momento la aplicación está utilizando el certificado del servidor, ¿verdad?
  • ¿Y antes de las modificaciones estaba usando también la mía?

¿Alguien puede explicarme cómo funciona esto?

Editar: Después de muchos correos electrónicos intercambiados con la empresa de alojamiento resultó que tenían problemas con su software de FTP y no hubo ningún problema con el código.

+1

Luego publique su edición como la respuesta y acéptelo. –

Respuesta

1

¿Ha comprobado si su host está utilizando FTPS o SFTP?

son protocolos diferentes y es posible que su servidor haya asumido que estaba hablando del incorrecto.

+0

Gracias por la respuesta. Trabajé junto con la empresa de hosting y el problema se resolvió. Resultó ser la configuración de su entorno. – mosu

+0

^¿Su entorno de alojamiento sería EC2 Amazon cloud hosting? – D3vtr0n

Cuestiones relacionadas