• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 919
  • Last Modified:

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

I have a C# application to upload a file which returns the message "the remote name could not be resolved: ftp.xxxxx.com".   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 ftp.xxxxx.com 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 = "ftp://ftp.xxxxx.com";
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);
stream.Close();
 
//Upload file
Stream reqStream = request.GetRequestStream();
reqStream.Write(buffer, 0, buffer.Length);
reqStream.Close();
MessageBox.Show("Uploaded Successfully");

Open in new window

0
mfb022800
Asked:
mfb022800
  • 3
  • 2
2 Solutions
 
GiftsonDJohnCommented:
If they are using Proxy then you have to pass the proxy details in Request.Proxy along with the Proxy Credentials.
0
 
williamcampbellCommented:
You are actually disabling automatic proxy detection by setting .proxy to null

http://msdn.microsoft.com/en-us/library/fze2ytx2(VS.80).aspx

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.
0
 
mfb022800Author Commented:
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?  
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
williamcampbellCommented:
Remove the .Proxy = null line
0
 
mfb022800Author Commented:
When that line is commented out the app displays the following:
The requested ftp command is not supported when using HTTP proxy
0
 
mfb022800Author Commented:
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.
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now