Solved

FTP Send File

Posted on 2014-03-21
3
354 Views
Last Modified: 2014-03-24
I am working my way through a piece of code debugging it

   


        Dim FTPServer As String = "ftp://ukftp.alyanto.com"
        Dim UserName As String = "alyanto"
        Dim Password As String = "expertsexchange"
        Dim FilePath As String = "C:\Users\tongcheeka\Documents\Adware\ScannerImport\FTPExport\Bad00021032014141633.csv"

       

        Try
            Dim oURI As New System.Uri(FTPServer)

            Dim fwr As FtpWebRequest = DirectCast(FtpWebRequest.Create(oURI), FtpWebRequest)
            fwr.Method = WebRequestMethods.Ftp.UploadFile
            fwr.Credentials = New NetworkCredential(.UserName, Password)
            fwr.Proxy = Nothing
            fwr.UsePassive = False
            Dim reader As New FileStream(oFTP.SourceFile, FileMode.Create, FileAccess.ReadWrite)
            Dim buffer(Convert.ToInt32(reader.Length - 1)) As Byte
            reader.Read(buffer, 0, buffer.Length)
            reader.Close()
            fwr.ContentLength = buffer.Length
            Dim stream As Stream = fwr.GetRequestStream
            stream.Write(buffer, 0, buffer.Length)
            stream.Close()

        Catch ex As Exception
            Debug.Print(ex.Message)
            Throw ex
        End Try

Open in new window


At Dim stream As Stream = fwr.GetRequestStream it throws this error

 'The requested URI is invalid for this FTP command.  

The team I am with believe the URL we are using is correct.  I can use it to navigate to using the URL via windows.  I suspect it is some combination of the URL and file name I need but I keep finding myself at a dead end.

Can someone make suggestion on how I might resolve the issue?
0
Comment
Question by:Alyanto
  • 2
3 Comments
 
LVL 74

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
ID: 39945337
Include the target filename in your URL before you create the FtpWebRequest.

e.g.

Dim FTPServer As String = "ftp://ukftp.alyanto.com/somefile.data"

Open in new window

0
 

Author Comment

by:Alyanto
ID: 39945665
Craq on mate, Cheers /Aly
0
 

Author Closing Comment

by:Alyanto
ID: 39950942
Thank you again
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

708 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

16 Experts available now in Live!

Get 1:1 Help Now