ftp to ws host

Posted on 2009-04-19
Last Modified: 2013-12-09
Hi All,
I have written a program to create web pages and I want to ftp the finished page tp the web server when they are finished.  The code hangs up on this line
       Dim clsStream As System.IO.Stream = clsRequest.GetRequestStream()
with the error message...

System.Net.WebException was unhandled
  Message="The remote server returned an error: (550) File unavailable (e.g., file not found, no access)."
       at System.Net.FtpWebRequest.SyncRequestCallback(Object obj)
       at System.Net.FtpWebRequest.RequestCallback(Object obj)
       at System.Net.CommandStream.InvokeRequestCallback(Object obj)
       at System.Net.CommandStream.Abort(Exception e)
       at System.Net.FtpWebRequest.FinishRequestStage(RequestStage stage)
       at System.Net.FtpWebRequest.GetRequestStream()
       at WebBuilder.Form4.Button5_Click(Object sender, EventArgs e) in C:\WebBuilder\WebBuilder\WebBuilder\Form4.vb:line 78
       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(Int32 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(ApplicationContext context)
       at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
       at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
       at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
       at WebBuilder.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
       at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
       at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
       at System.Runtime.Hosting.ManifestRunner.Run(Boolean checkAptModel)
       at System.Runtime.Hosting.ManifestRunner.ExecuteAsAssembly()
       at System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext, String[] activationCustomData)
       at System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext)
       at System.Activator.CreateInstance(ActivationContext activationContext)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssemblyDebugInZone()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()

The web host is hosting two domains so I need to choose which one the file goes to, hense the line
        DirectCast(System.Net.WebRequest.Create("ftp://" & s1 & "/" & s1), System.Net.FtpWebRequest)
where the first s1 is the domain name and the second s1 is the directory for the domain.  They just happen to have the same bane.  It appears the program is making a connection with the server but for some reason not accepting the file upload.

Can anyone tell me whaat I am doing wrong?
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click

        Dim s1, s2, s3, s4 As String

        ' set up request...

        s1 = Form1.TextBox3.Text

        s2 = Form1.TextBox1.Text & "\" & Form1.TextBox14.Text

        s3 = Form1.TextBox4.Text

        s4 = Form1.TextBox5.Text

        Dim clsRequest As System.Net.FtpWebRequest = _

        DirectCast(System.Net.WebRequest.Create("ftp://" & s1 & "/" & s1), System.Net.FtpWebRequest)

        clsRequest.Credentials = New System.Net.NetworkCredential(s3, s4)

        clsRequest.Method = System.Net.WebRequestMethods.Ftp.UploadFile

        ' read in file...

        Dim bFile() As Byte = System.IO.File.ReadAllBytes(s2)

        ' upload file...

'Hangs up with error message on following line

        Dim clsStream As System.IO.Stream = clsRequest.GetRequestStream()

        clsStream.Write(bFile, 0, bFile.Length)



    End Sub

End Class

Open in new window

Question by:dr_roose
    LVL 57

    Accepted Solution

    Do you have access to the ftp servers logs?  You may want to install something like wireshark ( and do a packet capture from your computer to verify what you are sending out.

    The 550 error message means you are attempting to write to a directory that you either do not have permission to write to or does not exist, it can also mean you are attempting to over write and existing file that you do not have permission to write to.

    One problem could be that the ftp server and web server have a different default starting location.


    Author Closing Comment

    Thank you very much.  I now have ftp capability

    Featured Post

    Gigs: Get Your Project Delivered by an Expert

    Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

    Join & Write a Comment

    Suggested Solutions

    Understanding FTPS File transfer is a common requirement in most Enterprises. While there are numerous ways to get a file from Point A to Point B over a network, perhaps the most common method still in use is FTP – File Transfer Protocol. FTP is …
    We recently endured a series of broadcast storms that caused our ISP to shut us down for brief periods of time. After going through a multitude of tests, we determined that the issue was related to Intel NIC drivers on some new HP desktop computers …
    After creating this article (, I decided to make a video (no audio) to show you how to configure the routers and run some trace routes and pings between the 7 sites…
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    24 Experts available now in Live!

    Get 1:1 Help Now