FTP File in

Posted on 2007-10-19
Last Modified: 2013-11-29
I am trying to send a single file from my website to another server via FTP, reference the code here:

Here is the code converted to for my needs:
Public Sub uploadFileUsingFTP(ByVal CompleteFTPPath As String, ByVal CompleteLocalPath As String, Optional ByVal UName As String = "", Optional ByVal PWD As String = "")

            Dim ftp As FtpWebRequest = FtpWebRequest.Create(CompleteFTPPath)
            ftp.Credentials = New NetworkCredential(UName, PWD)
            ftp.UseBinary = True
            ftp.Method = WebRequestMethods.Ftp.UploadFile
            ftp.KeepAlive = False

            Dim buff As Byte()
            Using f As FileStream = DirectCast(File.OpenRead(CompleteLocalPath), FileStream)
                buff = New Byte(f.Length - 1) {}
                f.Read(buff, 0, buff.Length)
            End Using

            Using stream As Stream = ftp.GetRequestStream()
                stream.Write(buff, 0, buff.Length)
            End Using

        End Sub

When I try to run this code I get the following error:
Unable to cast object of type 'System.Net.HttpWebRequest' to type 'System.Net.FtpWebRequest'
on this line of code:
Dim ftp As FtpWebRequest = FtpWebRequest.Create(CompleteFTPPath)

Why?  Anyone?
Question by:alivemedia
    LVL 21

    Expert Comment

    what is the value of the CompleteFTPPath you are passing to the function?
    LVL 21

    Accepted Solution

    My guess is that this path is a HTTP url
    LVL 2

    Author Comment

    ummm, yep.

    DOH!!!!  I just had to change the http to ftp!

    thanks for clueing me in!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    Suggested Solutions

    The article explains the protocols and technology which is involved when two computers on different TCP/IP networks communicate with each other. In the diagram, a router is used to segregate two networks. The networks are and 192…
    This is the first one of a series of articles I’ll be writing to address technical issues that are always referred to as network problems. The network boundaries have changed, therefore having an understanding of how each piece in the network  puzzl…
    Viewers will learn how to properly install and use Secure Shell (SSH) to work on projects or homework remotely. Download Secure Shell: Follow basic installation instructions: Open Secure Shell and use "Quick Connect" to enter credentials includi…
    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…

    737 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

    22 Experts available now in Live!

    Get 1:1 Help Now