I use this code to connect to FTP Account:
ftpRequest = (FtpWebRequest)FtpWebRequest.Create(host + "/" + directory);
/* Log in to the FTP Server with the User Name and Password Provided */
ftpRequest.Credentials = new NetworkCredential(user, pass);
/* When in doubt, use these options */
ftpRequest.Proxy = null;
ftpRequest.UseBinary = true;
ftpRequest.UsePassive = true;
ftpRequest.KeepAlive = true;
/* Specify the Type of FTP Request */
ftpRequest.Method = WebRequestMethods.Ftp.ListDirectory;
/* Establish Return Communication with the FTP Server */
ftpResponse = (FtpWebResponse)ftpRequest.GetResponse();
I use the same code to connect to 4 accounts and everything is okay except for one. For this account execution always returns this exception: ERROR REMOTE SERVER: (331) 331 User name okay, need password. The strange fact is that with the same credentials i am able to connect with FileZilla, so i am sure to use correct password and username for this account. I can't figure out what causes this problem.
Thank you in advance for any tips.
As Suggested i add below network log of .net and filezilla log. Network log is in italian language. I can see an error that sounds like 'URI REQUESTED IS NOT VALID FOR THIS FTP COMMAND'.
NETWORK LOG:
`System.Net Information: 0 : [7536] FtpWebRequest#31395883::.ctor(ftp://93.57.XX.XX/DIR_IN/)
System.Net Information: 0 : [7536] Tipo di installazione del sistema operativo corrente: 'Client'.
System.Net Information: 0 : [7536] FtpWebRequest#31395883::GetResponse(Metodo=NLST.)
System.Net Information: 0 : [7536] FtpControlStream#16919637 - Connessione creata da 192.168.1.5:1253 a 93.57.XX.XX:21.
System.Net Information: 0 : [7536] Associating FtpWebRequest#31395883 with FtpControlStream#16919637
System.Net Information: 0 : [7536] FtpControlStream#16919637 - Ricevuta risposta [220 Titan FTP Server 8.32.XXXX Ready.]
System.Net Information: 0 : [7536] FtpControlStream#16919637 - Invio comando [USER USERNAME] in corso...
System.Net Information: 0 : [7536] FtpControlStream#16919637 - Ricevuta risposta [331 User name okay, need password.]
System.Net Information: 0 : [7536] FtpWebRequest#31395883::(Rilascio connessione FTP n. 16919637.)
System.Net Error: 0 : [7536] Exception in FtpWebRequest#31395883::GetResponse - Errore del server remoto: (331) 331 User name okay, need password.
..
in System.Net.FtpWebRequest.CheckError()
in System.Net.FtpWebRequest.SyncRequestCallback(Object obj)
in System.IO.Stream.Close()
in System.Net.ConnectionPool.Destroy(PooledStream pooledStream)
in System.Net.ConnectionPool.PutConnection(PooledStream pooledStream, Object owningObject, Int32 creationTimeout, Boolean canReuse)
in System.Net.FtpWebRequest.FinishRequestStage(RequestStage stage)
in System.Net.FtpWebRequest.GetResponse()
System.Net Information: 0 : [7536] FtpWebRequest#54861376::.ctor(ftp://93.57.XX.XX/)
System.Net Information: 0 : [7536] FtpWebRequest#54861376::GetResponse(Metodo=RETR.)
System.Net Information: 0 : [7536] RAS supportato: True
System.Net Information: 0 : [7536] FtpControlStream#34723915 - Connessione creata da 192.168.1.5:1254 a 93.57.XX.XX:21.
System.Net Information: 0 : [7536] Associating FtpWebRequest#54861376 with FtpControlStream#34723915
System.Net Information: 0 : [7536] FtpWebRequest#54861376::(Rilascio connessione FTP n. 34723915.)
System.Net Error: 0 : [7536] Exception in FtpWebRequest#54861376::GetResponse - URI richiesto non valido per questo comando FTP..
in System.Net.FtpWebRequest.CheckError()
in System.Net.FtpWebRequest.GetResponse()
` FILEZILLA LOG:
2015-11-21 18:49:03 4968 3 Status: Connecting to 93.57.XX.XX:21...
2015-11-21 18:49:03 4968 3 Status: Connection established, waiting for welcome message...
2015-11-21 18:49:03 4968 3 Response: 220 Titan FTP Server 8.32.XXXX Ready.
2015-11-21 18:49:03 4968 3 Command: USER USERNAME
2015-11-21 18:49:03 4968 3 Response: 331 User name okay, need password.
2015-11-21 18:49:03 4968 3 Command: PASS ********
2015-11-21 18:49:03 4968 3 Response: 230-Welcome USERNAME from 151.20.XX.XX. You are now logged in to the server.
2015-11-21 18:49:03 4968 3 Response: 230 User logged in, proceed.
2015-11-21 18:49:03 4968 3 Command: SYST
2015-11-21 18:49:03 4968 3 Response: 215 UNIX Type: L8
2015-11-21 18:49:03 4968 3 Command: FEAT
2015-11-21 18:49:03 4968 3 Response: 211-Extensions Supported
2015-11-21 18:49:03 4968 3 Response: COMB
2015-11-21 18:49:03 4968 3 Response: MLST type*;size*;modify*;create*;perm*;
2015-11-21 18:49:03 4968 3 Response: SIZE
2015-11-21 18:49:03 4968 3 Response: MDTM
2015-11-21 18:49:03 4968 3 Response: MFMT
2015-11-21 18:49:03 4968 3 Response: MFCT
2015-11-21 18:49:03 4968 3 Response: EPRT
2015-11-21 18:49:03 4968 3 Response: EPSV
2015-11-21 18:49:03 4968 3 Response: XCRC
2015-11-21 18:49:03 4968 3 Response: REST STREAM
2015-11-21 18:49:03 4968 3 Response: AUTH SSL
2015-11-21 18:49:03 4968 3 Response: AUTH TLS
2015-11-21 18:49:03 4968 3 Response: CCC
2015-11-21 18:49:03 4968 3 Response: PBSZ
2015-11-21 18:49:03 4968 3 Response: PROT
2015-11-21 18:49:03 4968 3 Response: DQTA
2015-11-21 18:49:03 4968 3 Response: 211 End
2015-11-21 18:49:03 4968 3 Status: Connected
2015-11-21 18:49:03 4968 3 Status: Retrieving directory listing...
2015-11-21 18:49:03 4968 3 Command: PWD
2015-11-21 18:49:03 4968 3 Response: 257 "/" is current directory.
2015-11-21 18:49:03 4968 3 Command: TYPE I
2015-11-21 18:49:03 4968 3 Response: 200 Type set to I.
2015-11-21 18:49:03 4968 3 Command: PASV
2015-11-21 18:49:03 4968 3 Response: 227 Entering Passive Mode (93,57,XX,XX,15,131).
2015-11-21 18:49:03 4968 3 Command: MLSD
2015-11-21 18:49:03 4968 3 Response: 150 File status okay; about to open data connection.
2015-11-21 18:49:03 4968 3 Response: 226 Closing data connection. Transferred 414 bytes.
2015-11-21 18:49:03 4968 3 Status: Directory listing successful