Solved

Sending a file using FTP

Posted on 2014-11-27
4
127 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 74

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 74

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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

705 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

17 Experts available now in Live!

Get 1:1 Help Now