[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1591
  • Last Modified:

FTP File in ASP.net

I am trying to send a single file from my website to another server via FTP, reference the code here:
http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/Q_22099894.html

Here is the code converted to vb.net 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?
0
alivemedia
Asked:
alivemedia
  • 2
1 Solution
 
surajgupthaCommented:
what is the value of the CompleteFTPPath you are passing to the function?
0
 
surajgupthaCommented:
My guess is that this path is a HTTP url
0
 
alivemediaAuthor Commented:
ummm, yep.

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

thanks for clueing me in!
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now