Problema autenticazione proxy tramite ftpWebRequest

venerdì 30 ottobre 2009 - 15.36

davideb Profilo | Newbie

Salve a tutti,
Presso un cliente abbiamo un eseguibile c# realizzato con VS2005 che si connette periodicamente a un sito FTP ed effettua il download dei files in una cartella in locale.. fino a ieri funzionava, poi ha cominciato a dare questo errore:

407 Proxy Authentication required

il codice originale e' questo:
reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(ConfigurationManager.AppSettings["FTPPath"].ToString()));
reqFTP.Credentials = new NetworkCredential(ConfigurationManager.AppSettings["FTPUserName"].ToString(), ConfigurationManager.AppSettings["FTPPassword"].ToString());
reqFTP.Method = WebRequestMethods.Ftp.ListDirectory;
WebResponse response = reqFTP.GetResponse();
StreamReader reader = new StreamReader(response.GetResponseStream());
Log( "Connessione FTP OK");

Ho fatto un po' di troubleshoot dell'errore e trovato questo interessante articolo, linkato tra l'altro dal sito MSDN

http://forums.lhotka.net/forums/post/29271.aspx
http://msdn.microsoft.com/en-us/library/system.net.webproxy.aspx

Ho provato quindi a settare le impostazioni del proxy come suggerito ma senza risultati, l'errore che ottengo e' questo:

"The remote server returned an error: (400) Bad Request."

Il codice per la configurazione del proxy e' questo..

string proxyServerUrl = "http://myproxy.net".ToLower().Replace("http://", "");
System.Net.WebProxy proxy = new System.Net.WebProxy(proxyServerUrl,80);
proxy.UseDefaultCredentials = true;
proxy.Credentials = System.Net.CredentialCache.DefaultCredentials;

reqFTP.Proxy = proxy;

Qualche idea? Ho anche provato a definire manualmente username password e dominio (quindi commentando le righe 3 e 4) invece che usare le default credentials tramite questo comando ma niente....
proxy.Credentials = new System.Net.NetworkCredential("uteonte", "pwd","dominio");





Informazione aggiuntiva, la procedura si pianta al momento di fare la getResponse.... l'istruzuine prima (listdirectory) a quanto pare la esegue correttamente:

reqFTP.Method = WebRequestMethods.Ftp.ListDirectory;
WebResponse response = reqFTP.GetResponse();









Partecipa anche tu! Registrati!
Hai bisogno di aiuto ?
Perchè non ti registri subito?

Dopo esserti registrato potrai chiedere
aiuto sul nostro Forum oppure aiutare gli altri

Consulta le Stanze disponibili.

Registrati ora !
Copyright © dotNetHell.it 2002-2024
Running on Windows Server 2008 R2 Standard, SQL Server 2012 & ASP.NET 3.5