locked
FTPWebRequest .GetRequestStream() throws error 500 command unrecognized error

    Question

  • Hi

    I looked through the examples but they didn't quite seem to fit.  I have the below code and it <u>always</u> blows up on the GetRequestStream() line.  I can move it around (within reason of course) and it doesn't make a difference.  I get a 500 error, command unrecognized.  I have the ftp site configured to allow anyone (it is my own machine), the userid and password are correct (even though I am allowing anonymous connections) The file to upload resolves itself correctly into the Filestream.  I have some VS 2K5 code that will write to the FTP site but the goal is to get the code to work in 2K8.  Can anyone tell me what I am doing wrong?

    Many thanks.

    using

     

    System;

    using

     

    System.Collections.Generic;

    using

     

    System.Linq;

    using

     

    System.Text;

    using

     

    System.Net;

    using

     

    System.IO;

    using

     

    System.Diagnostics;

    using

     

    Microsoft.Practices.EnterpriseLibrary.Logging;


     

    FtpWebRequest request = (FtpWebRequest)FtpWebRequest.Create("ftp://" + FTPAddress + "/test/" + fileName);

     

    request.Method =

    WebRequestMethods.Ftp.UploadFile;

    request.Credentials =

    new NetworkCredential(userName, password);

    request.UsePassive =

    true;

    request.UseBinary =

    true;

    request.KeepAlive =

    false;

     

     

    // Loading the file

     

    FileStream stream = File.OpenRead(string.Format("{0}\\{1}",exportDir,fileName));

     

    byte[] buffer = new byte[stream.Length];

    stream.Read(buffer, 0, buffer.Length);

    stream.Close();

     

     

    // Uploading the file

     

    Stream reqStream = request.GetRequestStream();

    reqStream.Write(buffer, 0, buffer.Length);

    reqStream.Close();

     

     

     


    Tuesday, November 03, 2009 8:31 PM

All replies

  • Do you expect to change directory to "/test" and then do the upload?

    If so, see this post: http://social.msdn.microsoft.com/Forums/en-US/ncl/thread/2b9e3587-da00-40b8-8198-5561608d920e

    Otherwise, if that doesnt work, get a tracelog (see instructions in my signature). That should help figure out what is wrong...



    feroze
    --
    My blog
    Instruction on how to create a tracelog with your System.Net application
    Tuesday, November 03, 2009 11:00 PM
  • Do you expect to change directory to "/test" and then do the upload?

    If so, see this post: http://social.msdn.microsoft.com/Forums/en-US/ncl/thread/2b9e3587-da00-40b8-8198-5561608d920e

    Otherwise, if that doesnt work, get a tracelog (see instructions in my signature). That should help figure out what is wrong...



    feroze
    --
    My blog
    Instruction on how to create a tracelog with your System.Net application
    Tuesday, November 03, 2009 11:03 PM
  • Whats the complete error?  The full message, and ideally the full stack trace too. :-)
    http://www.alanjmcf.me.uk/ Please follow-up in the newsgroup. If I help, mark the question answered
    Wednesday, November 04, 2009 7:37 PM