none
"Bad Sequence of Commands" FTP Error

    Question

  • 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?

    Sunday, January 29, 2006 8:16 AM

Answers

  • 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.

    Sunday, January 29, 2006 8:32 AM

All replies

  • 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.

    Sunday, January 29, 2006 8:32 AM
  • 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

    Monday, April 24, 2006 12:19 PM
  • Tnx , i fixed it. I put it right after creating WebRequest
    Monday, April 24, 2006 12:22 PM
  • 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....
    Friday, December 15, 2006 10:07 AM
  • 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;

    }

    Monday, November 26, 2007 6:40 PM
  • Hello, I got the same problem with System.Net.WebClient.UploadFile(String address, String fileName)

    Error occurs : The remote server returned an error: (503) Bad sequence of commands.

    How do I solve this problem?  Many thanks in advance.
    Thursday, October 16, 2008 5:58 AM
  • Close and Reset the ftp connection after every ftp command when you are connecting to Unix ftp server... :)
    This should resolve the problem : "The remote server returned an error: (503) Bad sequence of commands"...
    This should work..........  :)
    Tuesday, November 24, 2009 6:39 AM
  • TakTeek.. Thanks you saved me on this one. I was good in dev until it went to a system test machine.  Apparently some machine keep connections open and some don't by default. I just started bashing ssis that was hosting my code until I read your post. Appreciate it.
    .NET developer
    Thursday, March 25, 2010 9:18 PM
  • Hi community,

    You saved my day, Takteek! Thumbs up!

    Tuesday, April 27, 2010 9:23 PM
  • hi,

     

    i have a same problem... i tried sevaral code but no success... can someone provide me the sample code for ftp(UNIX) uploading ...

     

    thanks

    sajjad


    C U On Net : sajjad_pexsol@yahoo.com
    Saturday, August 6, 2011 2:29 PM
  •  

     

    Thank you very much. I too fixed the issue by setting false to KeepAlive propery of request object.

    Monday, January 16, 2012 10:10 AM
  • @begeek99 +1 you are right , i was getting the same exception then i set KeepAlive to false and turns out it is very slow, i have done some math on this. and setting the KeepAlive flag to false will increase file transfer time by 43% on average. which is not acceptable when you are transferring hundreds of files, so this is not really a solution rather a workaround, still searching for a solution though
    Friday, February 3, 2012 6:09 PM
  • Abhijit K:

    I'm new to vb. Could you help me do that? lol. Here's my code:

     Dim create As System.IO.FileStream
            Dim server = "ftp://ftp.freehostia.com/UploadLocationDirectory/"
    
            create = System.IO.File.Create("C:/file.txt")
            create.Close()
    
            My.Computer.FileSystem.WriteAllText("C:/file.txt", TextBox1.Text, False)
    
            My.Computer.Network.UploadFile("C:/file.txt", server & "uploadedfile.html", "Username", "Password")
    
            My.Computer.FileSystem.DeleteFile("C:/file.txt")

    The code starts out by creating a new text file, then writing data to the new file, then uploading it to FTP, then deleting it off the computer.


    Sunday, November 11, 2012 7:32 PM
  • I have used WebClient.DownloadFile() before FtpWebRequest.Method = WebRequestMethods.Ftp.ListDirectory, then made WebResponse.GetResponse() throw the exception ever.

    Has no solution except replace WebClient.DownloadFile() by FtpWebRequest.Method = WebRequestMethods.Ftp.DownloadFile.

    Wednesday, September 16, 2015 8:50 AM
  • Hello, I got the same problem with System.Net.WebClient.UploadFile(String address, String fileName)

    Error occurs : The remote server returned an error: (503) Bad sequence of commands.

    How do I solve this problem?  Many thanks in advance.

    I have used WebClient.DownloadFile() before FtpWebRequest.Method = WebRequestMethods.Ftp.ListDirectory, then made WebResponse.GetResponse() throw the exception ever.

    Has no solution except replace WebClient.DownloadFile() by FtpWebRequest.Method = WebRequestMethods.Ftp.DownloadFile.

    I think you can replace WebClient.UploadFile() by FtpWebRequest.Method = WebRequestMethods.Ftp.UploadFile.

    Wednesday, September 16, 2015 8:53 AM