"Bad Sequence of Commands" FTP Error

I'm getting a strange error in my VB FTP program. It works fine when I download a file from an FTP server, but the second time that I download the same file i get "503 Bad Sequence of Commands".

If I download one file, download 3 other files, and then try to download the first file again, I get the error. If I close the program and open it again, the error is gone when I try to download the file.

Is there some command that I need to send the server to unlock the file or something



Answer this question

"Bad Sequence of Commands" FTP Error

  • Ken LC

    Yes it fixes the problem but it forces you to open and close the ftp connection for every operation, which is not acceptable when you have multiple operations to perform :-(

    This problem occurs only with a Unix ftp server, not with a Microsoft one. Thanks, Bill....

  • dziogo2

    I fixed it.

    If anyone is interested, I had to set the KeepAlive property of my request to false. Even thought the request object was destroyed, it was still keeping the connection to the file open.


  • 2wheels

    Tnx , i fixed it. I put it right after creating WebRequest

  • Ehsan_AIUB

    Hi
    I have the same problem as you had. but when i try to fix it with setting KeeAlive property to false i get an error saying " This operation cannot be performed after the request has been submitted." .I have it like this in my code:
    FtpWebResponse response = (FtpWebResponse)request.GetResponse();
    request.KeepAlive = false;

    and MSDN says

    "Changing KeepAlive after calling the GetRequestStream, BeginGetRequestStream, GetResponse, or BeginGetResponse method causes an InvalidOperationException exception."

    I don't know where i should put this line. I supposed that it should be right after i don't need the request anymore.Am i wrong

    Can you please help me

    Thanks


  • Ravana

    I am using a webclient object to download/upload multiple files to/from a remote ftp server. Sometimes it runs just fine and sometimes it gives me error : 503 bad sequence of commands. There is no "keepalive" property of the webclient which I can set to false according to the solution given above. How can I make sure that it will run fine everytime.

    private Exception Upload(WebClient client, string RemoteFile, string LocalFile)

    {

    Exception retErr = null;

    // Get the file name from the local file to name the file on the remote

    string Filename = Path.GetFileName(LocalFile);

    // Add the file name that the file will be called on the FTP site.

    string WebResources = RemoteFile + Filename;

    try

    {

    // Transfer the file to the FTP site.

    client.UploadFile(WebResources, LocalFile);

    }

    catch (Exception ex)

    {

    // If any errors occurred report it to the caller.

    retErr = ex;

    }

    return retErr;

    }


  • "Bad Sequence of Commands" FTP Error