FTP Upload Code fails but IE allows FTP Upload.  Does MS Proxy Server prevent code from working?

Posted on 2009-04-20
Last Modified: 2013-12-02
I have a C# application to upload a file which returns the message "the remote name could not be resolved:".   This problem only exists with one of my customers and a few dozen others don't have the problem, the code works for them.  This one customer can access using IE but not with my code and they are using MS Proxy Server.  Can MS Proxy server prevent this code from working but allows access using IE?  What do I have to do to get this code to work?
string FTPAddress = "";

string username = "valid username";

string password = "valid password";

//Create FTP request

FtpWebRequest request = (FtpWebRequest)FtpWebRequest.Create(new Uri(FTPAddress + "/" + Path.GetFileName(filePath)));

request.Method = WebRequestMethods.Ftp.UploadFile;

request.Credentials = new NetworkCredential(username, password);

request.UsePassive = true;

request.UseBinary = true;

request.KeepAlive = false;

request.Proxy = null;

//Load the file

FileStream stream = File.OpenRead(filePath);

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

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


//Upload file

Stream reqStream = request.GetRequestStream();

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


MessageBox.Show("Uploaded Successfully");

Open in new window

Question by:mfb022800
    LVL 14

    Accepted Solution

    If they are using Proxy then you have to pass the proxy details in Request.Proxy along with the Proxy Credentials.
    LVL 12

    Assisted Solution

    You are actually disabling automatic proxy detection by setting .proxy to null

    By default, the Internet Explorer proxy settings are used to detect the proxy. If your application is running under a non-interactive account (without a convenient way to configure IE proxy settings), or if you want to use proxy settings different than the IE settings, you can configure your proxy by creating a configuration file with the <defaultProxy> Element (Network Settings) and <proxy> Element (Network Settings) elements defined.

    Author Comment

    Thanks, I followed the link but can you show me the code change or explain to me how I would fit that into my code?  
    LVL 12

    Expert Comment

    Remove the .Proxy = null line

    Author Comment

    When that line is commented out the app displays the following:
    The requested ftp command is not supported when using HTTP proxy

    Author Closing Comment

    Thanks guys.  This ftp proxy issue is more of a problem than I hoped it would be so I decided to use Web Services instead.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    HOW TO REMOTELY CLEAN MEROND.O WITH ESET SILENTLY PROBLEM       If you have the fortunate luck to contract the Merond.O virus on your network, it can be quite troublesome to remove as it propagates to network shares on your network. In my case, the …
    Preface There are many applications where some computing systems need have their system clocks running synchronized within a small margin and eventually need to be in sync with the global time. There are different solutions for this, i.e. the W3…
    how to add IIS SMTP to handle application/Scanner relays into office 365.
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now