Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.Net: FtpWebRequest "(503) Bad sequence of commands" error

Tags:

c#

.net

ftp

On large files (~200+ MB), I get the 503 error when I read the stream.

ftp = (FtpWebRequest)WebRequest.Create(new Uri(address.AbsoluteUri + @"/" + file.Name));
ftp.Credentials = new NetworkCredential(username, password);
ftp.Method = WebRequestMethods.Ftp.DownloadFile;

response = (FtpWebResponse)ftp.GetResponse();

Any clues on what I'm doing wrong or a better practice for larger files?

like image 763
Austin Salonen Avatar asked Oct 31 '08 04:10

Austin Salonen


2 Answers

Do you receive the 503 after every attempt or only subsequent attempts?

Have you tried setting the disabling KeepAlive?

ftp.KeepAlive = false;

I would try a more rubust ftp client library, a basic free one can be at sourceforge.

like image 151
John Lemp Avatar answered Sep 29 '22 23:09

John Lemp


I'd concur that minimizing the number of NetworkCredential objects solves the problem. I experienced this problem and created a single CredentialCache and added each credential once. No more ftp errors.

like image 33
bmacadam Avatar answered Sep 29 '22 22:09

bmacadam