Solved

FTP Send File

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Simple Injector with Web Service 4 41
Search an image for an image 3 30
vb.net 1 month apart 11 29
VB.NET 2008 - SQL Timeout 9 24
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
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…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

772 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