Solved

FTP Send File

Posted on 2014-03-21
3
358 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 75

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
 
LVL 1

Author Comment

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

Author Closing Comment

by:Alyanto
ID: 39950942
Thank you again
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
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…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

697 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