Quantcast
Channel: Visual C# forum
Viewing all articles
Browse latest Browse all 31927

Using FtpWebRequest all of a sudden gives me this error "The Requested FTP Command Is Not Supported When Using HTTP Proxy."

$
0
0

Hi!

For a long time ago I wrote a program in .NET 2.0 that simply should upload/download files to/from an FTP server.

The program is running on Windws 7 with internet explorer 9. The admin had made a setting in the internetexplorer options to use a Proxy server and gave it a false address to stop the users surf on the net.

My program worked anyway, so far so good. But suddenly, everytime i try to send i get "The Requested FTP Command Is Not Supported When Using HTTP Proxy." as en exception from my program.

I tried to uncheck, clear all proxy settings, clear all cachefiles (from the internet explorer settings options).

But it still didn't work. Any idea what i should do?

This is the code i use.

       public bool Upload(string fileName, string destPath, out int MessageID, out string MessageText)
        {
            FileInfo fileInfo = new FileInfo(fileName);
            string uri = "ftp://" + FtpServerIP + destPath + fileInfo.Name;
            FtpWebRequest ftpServer;

            int bufferLength = 1024;
            byte[] buffer = new byte[bufferLength];
            int contentLength;


            try
            {
                // Prepare server for recieving file
                ftpServer = (FtpWebRequest)FtpWebRequest.Create(new Uri(uri));
                ftpServer.Credentials = new NetworkCredential(FtpUserID, FtpPassword);
                ftpServer.KeepAlive = false;
                ftpServer.Method = WebRequestMethods.Ftp.UploadFile;
                ftpServer.UseBinary = true;
                ftpServer.ContentLength = fileInfo.Length;

                FileStream fs = fileInfo.OpenRead();
                Stream stram = ftpServer.GetRequestStream();

                contentLength = fs.Read(buffer, 0, bufferLength);

                while (contentLength != 0)
                {
                    // Write to FTP Site
                    stram.Write(buffer, 0, contentLength);

                    // Read from file
                    contentLength = fs.Read(buffer, 0, bufferLength);
                }

                stram.Close();
                fs.Close();

                FtpWebResponse response = (FtpWebResponse)ftpServer.GetResponse();
                MessageID = (int)response.StatusCode;
                MessageText = response.StatusDescription;
                response.Close();

            }
            catch (WebException wes)
            {
                FtpWebResponse response = (FtpWebResponse)wes.Response;
                MessageID = (int)response.StatusCode;
                MessageText = response.StatusDescription;
                return false;
            }
            catch (Exception ex)
            {
                MessageID = 0;
                MessageText = ex.Message;
                return false;
            }

            return true;
        }

Any help is greatly appreciated.

Regards
Martin Arvidsson, Sweden


Viewing all articles
Browse latest Browse all 31927

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>