Solved

Sending a file using FTP

Posted on 2014-11-27
4
136 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
[X]
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
  • 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

Raise the IQ of Your IT Alerts

From IT major incidents to manufacturing line slowdowns, every business process generates insights that need to reach the people required to take action. You need a platform that integrates with your business tools to create fully enabled DevOps toolchains.

You need xMatters.

Question has a verified solution.

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

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…

691 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