Advertisement

01.11.2008 at 02:18PM PST, ID: 23077135
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

Webclient upload file to ftp server

Tags: c# net
FernandoSoto,
As I mentioned in another thread. I follow your code to upload a file to ftp server by webclient at my web application. I pass a file path to the function you posted. I got a exception 'An exception occurred during a WebClient request.' even trying to access my local develope machine which is set as ftp server also.

The code is:
private void UploadToFtp(string zpath)
{
      try
                  {
                        // String array to hold the full path of each file to be transfered
                        // to the FTP site.
                        string[] UploadFiles ={zpath}; // null;

                        // The web site URL
                        string remoteURI = "ftp://10.10.99.75/";
                        // Load files to this subdirectory
                        string placeFileInFolder ="NewStore/"; // "uploadfolder/";
                        // Create the FTP client
                        WebClient ftpClient = new WebClient();
                        // The user name and password are stored here
                        NetworkCredential nc = new NetworkCredential("mylog", "mypassword");
                        ftpClient.Credentials = nc;
                        // used to check if there were any errors in transfering the files
                        Exception err = null;

                        for (int idx = 0; idx < UploadFiles.Length; idx++)
                        {
                              // Call the function to transfer the files to the FTP site
                              err = xfer(ftpClient, remoteURI + placeFileInFolder, UploadFiles[idx]);
                              // Check to see if there were any errors in the transfer
                              if (err != null)
                              {
                                    // Write the error somewhere and reset err to null for the next transfer
                                    Response.Write(err.Message);
                                    err = null;
                              }
                        }
                  }
                  catch (Exception e)
                  {
                        myParam.Text="ERROR";
                        this.ERRMSG.Text=e.Message;
                  }
            }
        // client is the FTP client, remoteFile is where on the site the file will be
        // stored, localFile is the full path to the file going to be transfered
        // to the FTP site.
        private Exception xfer(WebClient client, string remoteFile, string localFile)
        {
            Exception retErr = null;
            // Get the file name from the local file to name the file on the remote
            string filename = Path.GetFileName(localFile);
            // Add the file name that the file will be called on the FTP site.
            string WebResources = remoteFile + filename;
            try
            {
                // Transfer the file to the FTP site.
                client.UploadFile(WebResources, localFile);
            }
            catch (Exception ex)
            {
                // If any errors occurred report it to the caller.
                retErr = ex;
            }
            return retErr;
        }      

Please help
Start your free trial to view this solution
Question Stats
Zone: Programming
Question Asked By: lanac222
Solution Provided By: lanac222
Participating Experts: 2
Solution Grade: B
Views: 354
Translate:
Loading Advertisement...
01.11.2008 at 03:45PM PST, ID: 20641788

Rank: Guru

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
01.14.2008 at 07:37AM PST, ID: 20653676

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
01.14.2008 at 07:54AM PST, ID: 20653820

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
01.14.2008 at 08:02AM PST, ID: 20653892

Rank: Guru

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
01.14.2008 at 08:14AM PST, ID: 20654011

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
01.14.2008 at 10:27AM PST, ID: 20655227

Rank: Guru

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
01.14.2008 at 11:21AM PST, ID: 20655733

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
01.14.2008 at 06:07PM PST, ID: 20659489

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
Loading Advertisement...
Microsoft
  • Internet Protocols
  • Applications
  • Development
  • OS
  • Hardware
  • Windows Security
Apple
  • Operating Systems
  • Hardware
  • Programming
  • Networking
  • Software
Internet
  • Search Engines
  • File Sharing
  • WebTrends / Stats
  • Spy / Ad Blockers
  • Web Browsers
  • New Net Users
  • Web Development
  • Chat / IM
  • Anti Spam
  • Web Servers
  • Anti-Virus
  • Email Clients
Gamers
  • Tips
  • Online / MMORPG
  • Puzzle
  • Emulators
  • Action / Adventure
  • Role Playing
  • Consoles
  • Game Programming
  • Strategy
  • Sports
  • Misc
  • Computer Games
Digital Living
  • Hardware
  • New Net Users
  • New Users
  • Software
  • Digital Music
  • Gaming World
  • Home Security
  • Apple
  • Networking Hardware
Virus & Spyware
  • Vulnerabilities
  • IDS
  • Encryption
  • Anti-Virus
  • Operating Systems Security
  • Software Firewalls
  • WebApplications
  • Cell Phones
  • Operating Systems
  • Internet
  • Hardware Firewalls
Hardware
  • Handhelds / PDAs
  • Displays / Monitors
  • Components
  • Networking Hardware
  • Peripherals
  • Laptops/Notebooks
  • Storage
  • Servers
  • Desktops
  • New Users
  • Misc
  • Apple
Software
  • System Utilities
  • Industry Specific
  • Network Management
  • Photos / Graphics
  • Page Layout
  • VMWare
  • Misc
  • Web Development
  • OS
  • CYGWIN
  • Voice Recognition
  • Message Queue
  • Quality Assurance
  • Security
  • Firewalls
  • MultiMedia Applications
  • Development
  • Database
  • Office / Productivity
  • Business Management
  • OS/2 Apps
  • Server Software
  • Internet / Email
ITPro
  • OS
  • Storage
  • Encryption
  • Operating Systems Security
  • Apple Hardware
  • Laptops & Notebooks
  • Servers
  • Networking Hardware
  • Peripherals
  • Devices
  • Displays / Monitors
  • WebTrends / Stats
  • Search Engines
  • Firewalls
  • WebApplications
  • IDS
  • Vulnerabilities
  • Email Clients
  • File Sharing
  • Spy / Ad Blockers
  • Web Browsers
  • Web Servers
  • Networking
  • Anti-Virus
  • Chat / IM
  • Anti Spam
Developer
  • Web Servers
  • Web Browsers
  • Game Programming
  • Dev Tools
  • Industry Specific
  • Office / Productivity
  • Database
  • CYGWIN
  • Web Development
  • Search Engines
  • File Sharing
  • WebTrends / Stats
  • Programming
  • Content Management
  • Application Servers
  • Protocols
Storage
  • Removable Backup Media
  • Storage Technology
  • Servers
  • Grid
  • Remote Access
  • Backup / Restore
  • Misc
  • Hard Drives
OS
  • Miscellaneous
  • Security
  • Development
  • Linux
  • VMWare
  • MainFrame OS
  • Unix
  • Apple
  • OS / 2
  • AS / 400
  • BeOS
  • Microsoft
  • VMS / OpenVMS
Database
  • Oracle
  • Miscellaneous
  • MySQL
  • Software
  • Sybase
  • Contact Management
  • PostgreSQL
  • Data Manipulation
  • Clarion
  • InterSystems Cache
  • Siebel
  • MUMPS
  • OLAP
  • SQLBase
  • SAS
  • GIS & GPS
  • 4GL
  • Berkeley DB
  • DB2
  • Informix
  • Interbase / Firebird
  • FoxPro
  • Reporting
  • LDAP
  • Filemaker Pro
  • MS SQL Server
  • dBase
  • MS Access
Security
  • Misc
  • Web Browsers
  • Software Firewalls
  • Operating Systems Security
  • File Sharing
  • Spy / Ad Blockers
  • Vulnerabilities
  • WebApplications
  • IDS
  • Anti-Virus
  • Encryption
  • Anti Spam
  • Email Clients
  • VPN
  • Chat / IM
Programming
  • Editors IDEs
  • Installation
  • Handhelds / PDAs
  • Multimedia Programming
  • System / Kernel
  • Algorithms
  • Game
  • Signal Processing
  • Project Management
  • Open Source
  • Database
  • Misc
  • Languages
  • Processor Platforms
  • Theory
Web Development
  • Scripting
  • Blogs
  • Web Servers
  • Software
  • Search Engines
  • Web Graphics
  • Images
  • Internet Marketing
  • Images and Photos
  • Components
  • Document Imaging
  • Web Languages/Standards
  • Illustration
  • WebApplications
  • Fonts
  • WebTrends / Stats
  • Authoring
  • Digital Camera Software
  • Miscellaneous
Networking
  • Protocols
  • Apple Networking
  • Network Management
  • Message Queue
  • Application Servers
  • Content Management
  • File Servers
  • Email Servers
  • Misc
  • Java Editors & IDEs
  • Wireless
  • Networking Hardware
  • Backup / Restore
  • System Utilities
  • ISPs & Hosting
  • Web Servers
  • Storage Technology
  • Removable Backup Media
  • Servers
  • Broadband
  • Grid
  • OS / 2
  • Novell Netware
  • Unix Networking
  • Windows Networking
  • Security
  • Telecommunications
  • Operating Systems
  • Linux Networking
Other
  • Community Advisor
  • Lounge
  • Community Support
  • New Net Users
  • Philosophy / Religion
  • Math / Science
  • Miscellaneous
  • URLs
  • Expert Lounge
  • Politics
  • Puzzles / Riddles
Community Support
  • Suggestions
  • New to EE
  • New Topics
  • Community Advisor
  • CleanUp
  • Announcements
  • General
  • Feedback
  • Input
  • EE Bugs
 
01.11.2008 at 03:45PM PST, ID: 20641788

Rank: Guru

I tried the code above and I was able to upload the file with no problem. It is hard to tell with the error message posted. Please try this, change the catch block in the xfer function from this:

            catch (Exception ex)
            {
                // If any errors occurred report it to the caller.
                retErr = ex;
            }

To this:

            catch (Exception ex)
            {
                // If any errors occurred report it to the caller.
                retErr = ex;
                using (StreamWriter sw = new StreamWriter("PathAndFilenameToWriteFileTO"))
                {
                    sw.WriteLine(ex.Message);
                    sw.WriteLine(ex.StackTrace);
                }

            }

Changing the StreamWriter parameter to a valid filename with path then run the program and post the contexts of the file.

Fernando
 
01.14.2008 at 07:37AM PST, ID: 20653676
FernandoSoto,
The exception raised at client.UploadFile(WebResources, localFile) of xfer function. It alway distroyed my local file. No matter what is the size or type of my local file it changed to 1kb of that type file and can not open any more. The file name doesn't change. Of course no file transfered.

lanac
 
01.14.2008 at 07:54AM PST, ID: 20653820
It distroyed my local file because I mistakely put the file path in
using (StreamWriter sw = new StreamWriter(localfile)). Now the local file is unchanged. but still same exception 'An exception occurred during a WebClient request.' and no file transfered.
 
01.14.2008 at 08:02AM PST, ID: 20653892

Rank: Guru

When an exception happens at this statement:

                // Transfer the file to the FTP site.
                client.UploadFile(WebResources, localFile);

In the xfer function it will be caught by the catch block that follows it. If you change that catch block to look like this:

            catch (Exception ex)
            {
                // If any errors occurred report it to the caller.
                retErr = ex;
                using (StreamWriter sw = new StreamWriter("PathAndFilenameToWriteFileTO"))
                {
                    sw.WriteLine(ex.Message);
                    sw.WriteLine(ex.StackTrace);
                }

And change this statement:

    using (StreamWriter sw = new StreamWriter("PathAndFilenameToWriteFileTO"))

So that PathAndFilenameToWriteFileTO is a valid file name to write to and then after you execute the code and the code fails then post the information in that file here. As I stated I have tested this code on my system and it works here. To be able to get an idea of what is happening I need to see the information in this file.

Fernando
 
01.14.2008 at 08:14AM PST, ID: 20654011
My application is NET 1.1. Is this the reason?
 
01.14.2008 at 10:27AM PST, ID: 20655227

Rank: Guru

Hi lanac;

Well normally I would say no seeming that it is supported on .Net Framework 1.1 but I just took the same code from my VS 2005 copy and past into VS 2003 .Net Framework 1.1 and I keep getting this error

Exception:
An exception occurred during a WebClient request.

Inner Exception in the above object:
The URI prefix is not recognized.

Meaning it did not like the web address. No matter what I do I can not make it work on .Net Framework 1.1 I am starting to think it may be a bugg in 1.1.

Fernando
 
01.14.2008 at 11:21AM PST, ID: 20655733
I created a class in 1.1 with socket and it works.
Accepted Solution
 
01.14.2008 at 06:07PM PST, ID: 20659489
A request has been made in Community Support to close this question:
http://www.experts-exchange.com/Q_23081774.html

If there are no objections, a moderator will finalize this question in approximately 4 days as follows:
PAQ with refund using {http:#a20655733}

Please only post in this question again if you have an objection.

Vee_Mod
Community Support Moderator
 
 
01.18.2008 at 09:20AM PST, ID: 20692147
Closed, 125 points refunded.
Lunchy
Friendly Neighbourhood Community Support Moderator
 
 
 
20080236-EE-VQP-29 / EE_QW_2_20070628