Subject: Issue in Upload/download FTP file via Proxy in ASP.NET 2.0 [C#]
Hello
How are you doing?
I am getting the following error when trying to FTP upload a file using FtpWebRequest via company proxy server.
"The requested FTP command is not supported when using HTTP proxy. "
Please suggest. as i am sure there should be a simple solution for this as it a very common proxy scenario
C# code is enclosed as below.
thanks
Naveen
using System.IO;
using System.Net;
namespace Bern.ISS.Web.Bloomberg
{
public class requestproc
{
public requestproc()
{
this._ftpServer = ConfigurationManager.AppSettings["FTP.Server"];
this._ftpPort = int.Parse(ConfigurationManager.AppSettings["FTP.Port"]);
this._ftpUser = ConfigurationManager.AppSettings["FTP.User"];
this._ftpPass = ConfigurationManager.AppSettings["FTP.Password"];
}
public static void SendRequest() //string filePath
{
try
{
string sFTPServer = "ftp://bfs.bloomberg.com/";
string sRemoteFile = "eodpricing_I.req";
string sURI = sFTPServer + sRemoteFile;
string sReqFile = ConfigurationManager.AppSettings["Bloomberg.Draft.Path"] + "\\eodpricing_I.req";
//Get the object used to communicate with the server
FtpWebRequest request = (FtpWebRequest)WebRequest.Create(sFTPServer);
//Set the proxy server login information
WebProxy wproxy = new WebProxy("ftppxy.xyzcompany.com");
wproxy.Credentials = new NetworkCredential("pxyuserid", "pxypasswd");
request.Proxy = wproxy;
//request.Proxy = null;
//Use logon information
request.Credentials = new NetworkCredential("bloomberguserid", "bloombergpwd");
request.KeepAlive = false;
request.UseBinary = true;
request.UsePassive = true;
request.Method = WebRequestMethods.Ftp.UploadFile;
// request.Method = WebRequestMethods.Ftp.DownloadFile;
// request.Method = WebRequestMethods.Ftp.MakeDirectory;
// Copy the contents of the file to the request stream.
// StreamReader sourceStream = new StreamReader(sReqFile);
// byte[] fileContents = Encoding.UTF8.GetBytes(sourceStream.ReadToEnd());
// sourceStream.Close();
// request.ContentLength = fileContents.Length;
FileStream streamObj = File.OpenRead(sReqFile);
byte[] buffer = new byte[streamObj.Length];
streamObj.Close();
streamObj = null;
//Upload File to
ftp://localHost/ set its object to nothing
request.GetRequestStream().Write(buffer, 0, buffer.Length);
// Stream requestStream = request.GetRequestStream();
// requestStream.Write(fileContents, 0, fileContents.Length);
// requestStream.Close();
FtpWebResponse response = (FtpWebResponse)request.GetResponse();
Console.WriteLine("Upload File Complete, status {0}", response.StatusDescription);
response.Close();
}
catch (Exception exc)
{
throw exc;
//throw new exception("Could not upload file to the FTP server.", exc);
}
}
}
}