Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old May 22nd, 2008, 06:27 PM
Registered User
 
Join Date: May 2008
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Issue in Upload/download FTP file via Proxy C#.NET

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);
            }
        }

    }
}


Reply With Quote
  #2 (permalink)  
Old May 26th, 2008, 10:50 PM
Registered User
 
Join Date: May 2008
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hello

Anybody has any idea using the .NET class library to call ftp upload/download functionality through a company proxy server.

Please let me know as I am looking for a solution.
If not a native .NET class library functionality, then any information on any 3rd party component control that can do the needful,. i.e. Call FTP upload/download via a proxy server in an ASP.NET C# page.

Thanks

Reply With Quote
  #3 (permalink)  
Old May 27th, 2008, 02:54 PM
Registered User
 
Join Date: May 2008
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hello

How are you doing?

I am looking for the following information to make a FTP call [via proxy] from a .NET program:

> The best practices followed for calling FTP through the corporate proxy server from a .NET C# Web page.
   Currently I tried using System.Net class library [.NET 2.0] to call ftp upload/download functionality through proxy, without success.

> Do we have some kind of Internal built-in native .NET class library functionality that address this issue?

> If not, then do we have any 3rd party component control that can call FTP upload/download via a proxy server in an ASP.NET C# page.

> Does FTP Voyager provide a class library to programmatically call FTP via proxy.

> Provide specific FTP Contact links on the web for further details.

Please let me know as I am looking for a solution to finalize our market data needs.

Thanks

Reply With Quote
  #4 (permalink)  
Old June 20th, 2008, 08:51 AM
Authorized User
 
Join Date: Jan 2008
Location: , , .
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Doom
Default

Found this example off the net. Its a windows form application not a console application. it will give you a rough idea of the syntax.

Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
//Needed
using System.IO;
using System.Net;

namespace DownloadData
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void lbVCKicks_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            System.Diagnostics.Process.Start("http://vckicks.110mb.com");
        }

        private byte[] downloadedData;

        private void downloadData(string url)
        {
            WebClient downloadClient = new WebClient();

            downloadedData = new byte[0];
            try
            {
                //Optional
                this.Text = "Connecting...";
                Application.DoEvents();

                //Get a data stream from the url
                WebRequest req = WebRequest.Create(url);
                WebResponse response = req.GetResponse();
                Stream stream = response.GetResponseStream();

                //Download in chuncks
                byte[] buffer = new byte[1024];

                //Get Total Size
                string dataLengthString = response.Headers["Content-Length"];
                int dataLength = 0;
                if (dataLengthString != null)
                {
                    dataLength = Convert.ToInt32(dataLengthString);
                }

                //With the total data we can set up our progress indicators
                progressBar1.Maximum = dataLength;
                lbProgress.Text = "0/" + dataLength.ToString();

                this.Text = "Downloading...";
                Application.DoEvents();

                //Download
                MemoryStream memStream = new MemoryStream();
                while (true)
                {
                    //Try to read the data
                    int bytesRead = stream.Read(buffer, 0, buffer.Length);

                    if (bytesRead == 0)
                    {
                        //Finished downloading
                        progressBar1.Value = progressBar1.Maximum;
                        lbProgress.Text = dataLength.ToString() + "/" + dataLength.ToString();

                        Application.DoEvents();
                        break;
                    }
                    else
                    {
                        //Write the downloaded data
                        memStream.Write(buffer, 0, bytesRead);

                        //Update the progress bar
                        if (progressBar1.Value + bytesRead <= progressBar1.Maximum)
                        {
                            progressBar1.Value += bytesRead;
                            lbProgress.Text = progressBar1.Value.ToString() + "/" + dataLength.ToString();

                            progressBar1.Refresh();
                            Application.DoEvents();
                        }                        
                    }
                }

                //Convert the downloaded stream to a byte array
                downloadedData = memStream.ToArray();

                //Clean up
                stream.Close();
                memStream.Close();
            }
            catch (Exception)
            {
                MessageBox.Show("There was an error accessing the url");
            }

            txtData.Text = downloadedData.Length.ToString();
            this.Text = "Download Data";
        }

        private void btnDownload_Click(object sender, EventArgs e)
        {
            downloadData(txtUrl.Text);

            //We just want to extract the name for the save dialog
            if (downloadedData.Length != 0)
            {
                string urlName = txtUrl.Text;
                if (urlName.EndsWith("/"))
                    urlName = urlName.Substring(0, urlName.Length - 1); //Chop off the last '/'

                urlName = urlName.Substring(urlName.LastIndexOf('/') + 1);

                saveDiag1.FileName = urlName;
            }
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            if (downloadedData.Length != 0)
            {
                if (saveDiag1.ShowDialog() == DialogResult.OK)
                {
                    this.Text = "Saving Data...";
                    Application.DoEvents();

                    //Write the bytes to a file
                    FileStream newFile = new FileStream(saveDiag1.FileName, FileMode.Create);
                    newFile.Write(downloadedData, 0, downloadedData.Length);
                    newFile.Close();

                    this.Text = "Download Data";
                    MessageBox.Show("Saved Successfully");
                }
            }
        }
    }
}
Here is the link for the snippet

http://vckicks.110mb.com/download_file_http.html
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
ftp file upload yugi9966 ADO.NET 1 August 7th, 2008 09:09 AM
FTP connection to a Proxy ajaypsingh Pro Java 0 July 14th, 2006 06:36 AM
Upload Of Excel file to FTP Site shahbazr4 Java Databases 0 May 2nd, 2005 04:01 AM
Deleting file after ftp download otarboy Pro VB 6 0 September 27th, 2004 03:58 AM
Automate the ftp Upload of a Comma-Delineated File darinsee Access ASP 0 February 11th, 2004 10:57 AM



All times are GMT -4. The time now is 02:25 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.