14 Replies - 1938 Views - Last Post: 08 May 2013 - 03:19 PM Rate Topic: -----

#1 aczwicker  Icon User is offline

  • New D.I.C Head
  • member icon

Reputation: 2
  • View blog
  • Posts: 35
  • Joined: 23-May 12

(550) File Unavailable when trying to upload to ftp

Posted 08 May 2013 - 10:49 AM

Hello all, I am creating an inventory program that, you guessed it, keeps track of inventory.
I am adding a feature for our sales department that takes the item name from its field and searches for that item on various websites to try to get a price point for marketing.

So I created this tool that brings up 3 sites with the item searched and displayed. Works great with Chrome, IE, Etc.

The Issue:
One of our sales guys doesn't use a tabular format in his web browser, so he suggested bringing up all 3 sites in tabular format using the web browser built in to Visual Studio (C#).

I found the field to change, but when I try to insert a URL i get the error:
Error 1 Cannot implicitly convert type 'string' to 'System.Uri'

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace InventorySystem
{
    public partial class Form1 : Form
    {
        //public Variables
        public string ItemName = "";

        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {

        }

        private void Form1_Load(object sender, EventArgs e)
        {
          

        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            ItemName = NewItemName.Text;
        }

        private void button1_Click_1(object sender, EventArgs e)
        {

        }

        //Button for "Lookup on Ebay"
        private void button4_Click(object sender, EventArgs e)
        {

            System.Diagnostics.Process.Start("http://www.ebay.com/sch/i.html?_trksid=p2050601.m570.l1313.TR0.TRC0&_nkw="+ItemName+"&_sacat=0&_from=R40");
            System.Diagnostics.Process.Start("www.terapeak.com");
            System.Diagnostics.Process.Start("http://www.nwrusa.com/"+ItemName+"_p/6358.htm");
        }

        private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
            //THIS IS WHERE IM GETTING THE ISSUE
            webBrowser1.Url = "www.google.com";
        }
    }
}



Am I missing something completely obvious?
I've never tried to change the built in browser URL except for in the Design Editor.

EDIT***

I have found code that works.

webBrowser1.Url = new System.Uri("http://www.ebay.com/sch/i.html?_trksid=p2050601.m570.l1313.TR0.TRC0&_nkw=" + ItemName + "&_sacat=0&_from=R40", System.UriKind.Absolute);


This post has been edited by aczwicker: 08 May 2013 - 10:52 AM


Is This A Good Question/Topic? 0
  • +

Replies To: (550) File Unavailable when trying to upload to ftp

#2 andrewsw  Icon User is offline

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3316
  • View blog
  • Posts: 11,188
  • Joined: 12-December 12

Re: (550) File Unavailable when trying to upload to ftp

Posted 08 May 2013 - 10:51 AM

webBrowser1.Url = "www.google.com";

You need to include "http://".
Was This Post Helpful? 0
  • +
  • -

#3 aczwicker  Icon User is offline

  • New D.I.C Head
  • member icon

Reputation: 2
  • View blog
  • Posts: 35
  • Joined: 23-May 12

Re: (550) File Unavailable when trying to upload to ftp

Posted 08 May 2013 - 10:55 AM

is there a way to close my own thread? I don't want to bother anyone with an answered question.
Was This Post Helpful? 0
  • +
  • -

#4 andrewsw  Icon User is offline

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3316
  • View blog
  • Posts: 11,188
  • Joined: 12-December 12

Re: (550) File Unavailable when trying to upload to ftp

Posted 08 May 2013 - 12:10 PM

View Postaczwicker, on 08 May 2013 - 05:55 PM, said:

is there a way to close my own thread? I don't want to bother anyone with an answered question.

It is not necessary. Besides, answered threads are extremely useful!

This post has been edited by andrewsw: 08 May 2013 - 12:11 PM

Was This Post Helpful? 0
  • +
  • -

#5 aczwicker  Icon User is offline

  • New D.I.C Head
  • member icon

Reputation: 2
  • View blog
  • Posts: 35
  • Joined: 23-May 12

Re: (550) File Unavailable when trying to upload to ftp

Posted 08 May 2013 - 02:15 PM

Hey everyone, I am trying to use C# to upload a file Via Ftp. I keep getting an error that it cant find the file yet I'm 90% sure that the path is correct.

Can anyone tell if i am missing anything?
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
using System.Net;

namespace InventorySystem
{
    public partial class Form1 : Form
    {
        //public Variables
        public string ItemName = "";

        public string sourcefilepath = ""; // e.g. “d:/test.docx”


        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {

        }

        private void Form1_Load(object sender, EventArgs e)
        {
          

        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            ItemName = NewItemName.Text;
        }

        private void button1_Click_1(object sender, EventArgs e)
        {

        }

        //Button for "Lookup on Ebay"
        private void button4_Click(object sender, EventArgs e)
        {
            /*
            System.Diagnostics.Process.Start("http://www.ebay.com/sch/i.html?_trksid=p2050601.m570.l1313.TR0.TRC0&_nkw="+ItemName+"&_sacat=0&_from=R40");
            System.Diagnostics.Process.Start("www.terapeak.com");
            System.Diagnostics.Process.Start("http://www.nwrusa.com/"+ItemName+"_p/6358.htm");
            */
            webBrowser1.Url = new System.Uri("http://www.ebay.com/sch/i.html?_trksid=p2050601.m570.l1313.TR0.TRC0&_nkw=" + ItemName + "&_sacat=0&_from=R40", System.UriKind.Absolute);
            webBrowser2.Url = new System.Uri("https://www.google.com/search?hl=en&tbm=shop&q=" + ItemName + "&oq=" + ItemName + "&gs_l=products-cc.3..0.3165.4948.0.5157.11.5.0.6.6.0.68.286.5.5.0...0.0...1ac.1.FjoqNgSVJZM", System.UriKind.Absolute);
            webBrowser3.Url = new System.Uri("http://www.nwrusa.com/SearchResults.asp?Search="+ItemName, System.UriKind.Absolute);
            pictureBox1.ImageLocation = @"http://www.nwrpics.com/images/" + ItemName + ".jpg";
            richTextBox1.Text = @"http://www.nwrpics.com/images/" + ItemName + ".jpg";
        }

        private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
            /*
            webBrowser1.Url = new System.Uri("http://www.ebay.com/sch/i.html?_trksid=p2050601.m570.l1313.TR0.TRC0&_nkw=" + ItemName + "&_sacat=0&_from=R40", System.UriKind.Absolute);
            webBrowser2.Url = new System.Uri("https://www.google.com/search?hl=en&tbm=shop&q="+ItemName+"&oq="+ItemName+"&gs_l=products-cc.3..0.3165.4948.0.5157.11.5.0.6.6.0.68.286.5.5.0...0.0...1ac.1.FjoqNgSVJZM", System.UriKind.Absolute);
            webBrowser3.Url = new System.Uri("http://www.ebay.com/sch/i.html?_trksid=p2050601.m570.l1313.TR0.TRC0&_nkw=" + ItemName + "&_sacat=0&_from=R40", System.UriKind.Absolute);
            */
        }

        private void webBrowser2_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {

        }

        private void button2_Click(object sender, EventArgs e)
        {

        }

        private void pictureBox1_Click(object sender, EventArgs e)
        {
            
        }

        private void richTextBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void folderBrowserDialog1_HelpRequest(object sender, EventArgs e)
        {

        }

        private static void UploadFileToFTP(string source)
        {
            String ftpurl = "ftp://nwrpics.com/images"; // e.g. ftp://serverip/foldername/foldername
            String ftpusername = "xxxxxxxx"; // e.g. username
            String ftppassword = "xxxxxxxxxx"; // e.g. password
            try
            {
                string filename = Path.GetFileName(source);
                string ftpfullpath = ftpurl;
                FtpWebRequest ftp = (FtpWebRequest)FtpWebRequest.Create(ftpfullpath);
                ftp.Credentials = new NetworkCredential(ftpusername, ftppassword);

                using (var resp = (FtpWebResponse)ftp.GetResponse())
                {
                    Console.WriteLine(resp.StatusCode);
                    System.Diagnostics.Debug.Write(resp.StatusCode);
                }

                ftp.KeepAlive = true;
                ftp.UseBinary = true;
                ftp.Method = WebRequestMethods.Ftp.UploadFile;

                FileStream fs = File.OpenRead(source);
                byte[] buffer = new byte[fs.Length];
                fs.Read(buffer, 0, buffer.Length);
                fs.Close();

                Stream ftpstream = ftp.GetRequestStream();
                ftpstream.Write(buffer, 0, buffer.Length);
                ftpstream.Close();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        private void button1_Click_2(object sender, EventArgs e)
        {
            // open file dialog 
            OpenFileDialog open = new OpenFileDialog();
            // image filters
            open.Filter = "Image Files(*.jpg;)|*.jpg;";
            if (open.ShowDialog() == DialogResult.OK)
            {
                // display image in picture box
                pictureBox1.Image = new Bitmap(open.FileName);
                // image file path
                label10.Text = open.FileName;
                sourcefilepath = open.FileName;
            } 
        }

        private void button3_Click(object sender, EventArgs e)
        {
            UploadFileToFTP(sourcefilepath);
        }
    }
}



Any help on this is much appreciated!
Was This Post Helpful? 0
  • +
  • -

#6 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5464
  • View blog
  • Posts: 11,731
  • Joined: 02-June 10

Re: (550) File Unavailable when trying to upload to ftp

Posted 08 May 2013 - 02:31 PM

Have you done even basic debugging?
What line does the exception occur on?




tlhIn`toq's FAQ list

Learning to debug one's own code is an essential skill. Sadly, one that apparently few college courses teach. Silly if you ask me.

Placing breakpoints and walking through the code line by line allows you to actually WATCH it execute.

Visualizing what your code does will let you see why it behaves the way it does.

It would be well worth your time to do the tutorials on FAQ 2. A couple hours learning this skill will save you hundreds of hours of confusion in one project alone.


TOP most asked:
What does this error message mean?
FAQ 2: How do I debug
FAQ 3: How do I make Class1/Form1 talk to Class2/Form2


FAQ (Frequently Asked Questions - Updated Apr 2013
Spoiler



Was This Post Helpful? 0
  • +
  • -

#7 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5464
  • View blog
  • Posts: 11,731
  • Joined: 02-June 10

Re: (550) File Unavailable when trying to upload to ftp

Posted 08 May 2013 - 02:43 PM

As a critique... Some of the basic concepts of building an application are missing here. These names like "button1" and "TextBox3" are totally rookie from the first day of class.

This method makes no sense to me. You're triggering on a change to text of textBox1 - but you're getting a value from NewItemName and shoving it into ItemName. What a mess of three different items for a single property! Where is NewItemName coming from?

039        private void textBox1_TextChanged(object sender, EventArgs e)
040        {
041            ItemName = NewItemName.Text;
042        }



This logic is just dirty. And its not needed. You don't have to track the file name as it is being changed. Just get it when you need it. When you are finally going to do the upload, THEN get the filename from either a property or from the textBox. But don't add unneeded complexity of real-time tracking for no purpose.

Forgive my frankness but... This looks like you're trying to architect a program from scratch with no experience in C#. You need to learn the language and work your way up to stuff like this. That's not fun, but it is reality. Work on lessons, not building and designing.

At the very least, go through the properties and classes tutorials I have linked in my signature block before moving on.



My standard beginner resources post - Updated Apr 2013


Plan your study route:
There are three routes people seem to take when learning programming.
  • Just start trying to create programs
  • Start taking apart other programs and try to figure out the language by reverse engineering
  • Follow a guided learning course (school or self-teaching books)


For the life of me I can't figure out why people try 1 & 2. I strongly suggest taking the guided learning approach. Those book authors go in a certain order for a reason: They know what they're doing and they know the best order to learn the materials.

  • First learn the language by working 2-5 "Learn C# in 30 days" type books cover to cover.
  • Do a dozen on-line tutorial projects where you build what you're told to build, the way you are told to build it WITH AN EXPLANATION OF WHY so you can learn.
  • Learn to plan before you type.
  • THEN you start designing software with a purpose.



I don't learn from reading books: I learn by doing.
Spoiler


Newbie/Rookie said:

I have little/no programming experience but I need to write a program by Friday that does XYZ.
Spoiler



Resources, references and suggestions for new programmers.
Spoiler


Please don't create multiple threads for what is essentially the same thing. Its obvious you are going to be asking a lot of questions over this one project and they are all related. Let's keep them all the same thread. I'm going to merge the two.

This post has been edited by tlhIn`toq: 08 May 2013 - 02:41 PM

Was This Post Helpful? 0
  • +
  • -

#8 aczwicker  Icon User is offline

  • New D.I.C Head
  • member icon

Reputation: 2
  • View blog
  • Posts: 35
  • Joined: 23-May 12

Re: (550) File Unavailable when trying to upload to ftp

Posted 08 May 2013 - 02:55 PM

The majority of the code was generated by Visual Studio as a Starting point, the part of the code that I am having issues with is simply the upload section.

The other code is default, not handwritten to be crap on purpose.
I actually have a background in program architecture and design, but in Java, not c#.

I am switching over to C# because unfortunately Java is a dying language.


Yes, I have stepped through the code and I get back a status code:

System.Net.FtpStatusCode.ActionNotTakenFileUnavailable
550 I can only retrieve regular files
Was This Post Helpful? 0
  • +
  • -

#9 andrewsw  Icon User is offline

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3316
  • View blog
  • Posts: 11,188
  • Joined: 12-December 12

Re: (550) File Unavailable when trying to upload to ftp

Posted 08 May 2013 - 03:00 PM

You still haven't told us which line the error occurs on.
It would also obviously be useful to create a string and print it out showing the full (constructed) file-path of the file that fails.
Was This Post Helpful? 0
  • +
  • -

#10 aczwicker  Icon User is offline

  • New D.I.C Head
  • member icon

Reputation: 2
  • View blog
  • Posts: 35
  • Joined: 23-May 12

Re: (550) File Unavailable when trying to upload to ftp

Posted 08 May 2013 - 03:01 PM

my bad, line 131 and 153 is what the debugger is telling me.

throw ex;

which doesn't help much, i know

System.Net.WebException was unhandled
HResult=-2146233079
Message=The remote server returned an error: (550) File unavailable (e.g., file not found, no access).
Source=InventorySystem
StackTrace:
at InventorySystem.Form1.UploadFileToFTP(String source) in c:\Users\Andrew\Documents\Visual Studio 2012\Projects\InventorySystem\InventorySystem\Form1.cs:line 131
at InventorySystem.Form1.button3_Click(Object sender, EventArgs e) in c:\Users\Andrew\Documents\Visual Studio 2012\Projects\InventorySystem\InventorySystem\Form1.cs:line 153
at System.Windows.Forms.Control.onclick(EventArgs e)
at System.Windows.Forms.Button.onclick(EventArgs e)
at System.Windows.Forms.Button.onmouseup(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativewindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativewindow.WndProc(Message& m)
at System.Windows.Forms.Nativewindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at InventorySystem.Program.Main() in c:\Users\Andrew\Documents\Visual Studio 2012\Projects\InventorySystem\InventorySystem\Program.cs:line 19
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:

This post has been edited by aczwicker: 08 May 2013 - 03:03 PM

Was This Post Helpful? 0
  • +
  • -

#11 andrewsw  Icon User is offline

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3316
  • View blog
  • Posts: 11,188
  • Joined: 12-December 12

Re: (550) File Unavailable when trying to upload to ftp

Posted 08 May 2013 - 03:03 PM

FtpWebRequest behaviour changed between Framework 3.5 and 4, which can cause 5xx errors. I've no idea if this is relevant to your issue, but I'll post the link just in case:

http://support.micro....com/kb/2134299
Was This Post Helpful? 1
  • +
  • -

#12 aczwicker  Icon User is offline

  • New D.I.C Head
  • member icon

Reputation: 2
  • View blog
  • Posts: 35
  • Joined: 23-May 12

Re: (550) File Unavailable when trying to upload to ftp

Posted 08 May 2013 - 03:11 PM

View Postandrewsw, on 08 May 2013 - 03:03 PM, said:

FtpWebRequest behaviour changed between Framework 3.5 and 4, which can cause 5xx errors. I've no idea if this is relevant to your issue, but I'll post the link just in case:

http://support.micro....com/kb/2134299


I think it could be related. I'll go through and convert the code to work specifically for Framework 4 and see if it makes a difference.

View Postandrewsw, on 08 May 2013 - 03:00 PM, said:

You still haven't told us which line the error occurs on.
It would also obviously be useful to create a string and print it out showing the full (constructed) file-path of the file that fails.


This I have done,
label10.Text = open.FileName;



Its the correct path so I was thinking it could be a permission issue. But no other processes are using the file so Im not sure why it wouldn't have permission.
Was This Post Helpful? 0
  • +
  • -

#13 andrewsw  Icon User is offline

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3316
  • View blog
  • Posts: 11,188
  • Joined: 12-December 12

Re: (550) File Unavailable when trying to upload to ftp

Posted 08 May 2013 - 03:17 PM

open.FileName is not what you are using when you make the WebRequest. It is ftpfullpath, which is the same as ftpurl.
Was This Post Helpful? 0
  • +
  • -

#14 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5464
  • View blog
  • Posts: 11,731
  • Joined: 02-June 10

Re: (550) File Unavailable when trying to upload to ftp

Posted 08 May 2013 - 03:18 PM

View Postaczwicker, on 08 May 2013 - 04:01 PM, said:

my bad, line 131 and 153 is what the debugger is telling me.

throw ex;

which doesn't help much, i know


129            catch (Exception ex)
130            {
131                throw ex;
132            }



It would help a lot if you would look at the details of the message. The instance of the exception is ex. It has a lot of details if you'd examine it.
Was This Post Helpful? 0
  • +
  • -

#15 andrewsw  Icon User is offline

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3316
  • View blog
  • Posts: 11,188
  • Joined: 12-December 12

Re: (550) File Unavailable when trying to upload to ftp

Posted 08 May 2013 - 03:19 PM

Personally, I would disable the try..catch block and step through the code, before making the more dramatic changes (possibly) that you mentioned in your previous post.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1