Solved

Sending a file using FTP

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.

863 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

22 Experts available now in Live!

Get 1:1 Help Now