Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Sending a file using FTP

Posted on 2014-11-27
4
132 Views
Last Modified: 2014-11-27
I'm trying to send a file using the following block of code.  How do I send a file to a specific folder on the server using this code?

' Sample Call
dim sourceFileName as string
dim targetfileName as uri

SendFile(sourceFileName, targetfileName)

   Shared Sub SendFile(sourcefileName As String, targetfileName As Uri)
      request = DirectCast(FtpWebRequest.Create(targetfileName), FtpWebRequest)

      With request
         .Method = WebRequestMethods.Ftp.UploadFile
         .UsePassive = True
         .UseBinary = True
         .KeepAlive = True
      End With

      Using fileStream As FileStream = File.OpenRead(sourcefileName)
         Dim buffer As Byte() = New Byte(fileStream.Length - 1) {}

         fileStream.Read(buffer, 0, buffer.Length)

         With request.GetRequestStream()
            .Write(buffer, 0, buffer.Length)
            .Close()
         End With

         response = request.GetResponse
      End Using
   End Sub

Open in new window

0
Comment
Question by:Ray Turner
  • 2
  • 2
4 Comments
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
ID: 40469959
The URI that you pass in to the FtpWebRequest.Create should have the specific path you want to upload to. For example, if you had file "test.txt" and you wanted it to go into the "DummyFiles" folder, then your request creation would look like:

FtpWebRequest.Create("ftp.example.com/DummyFiles/test.txt")

Open in new window

0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 40469960
Actually, how is this different than your previous question?
0
 

Author Comment

by:Ray Turner
ID: 40470015
I was using a 3rd Party product (FTP/.NET Library).  The syntax they used was quite different from what I'm seeing here.  I guess a lot of this stuff was being taken care of behind the scenes.  I'm trying to learn how to use the built-in capabilities of .Net Framework 4.5 to accomplish the same thing.
0
 

Author Closing Comment

by:Ray Turner
ID: 40470017
Thanks!
0

Featured Post

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

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

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

792 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