Home > Articles > Programming > Windows Programming

  • Print
  • + Share This
Like this article? We recommend

Like this article? We recommend

Downloading and Uploading Files

An exciting feature for any programmer these days is the ability to interact with the Internet. At least once a week, I get email from people who want to upload and download files using FTP. You can labor tediously and write your own FTP client, or you can use the My feature’s My.Computer.Network namespace and move files across the Internet with just a few lines of code (see Listing 8).

Listing 8 Download a file from the Internet using ftp:// and check for a successful result.

Sub UploadAndDownloadFile()
 Const filename As String = "c:\temp\welcome.txt"
 If (My.Computer.FileSystem.FileExists(filename)) Then
 End If

 My.Computer.Network.DownloadFile( _
  "ftp://ftp.softconcepts.com/Welcome.txt", "c:\temp\welcome.txt")
 If (My.Computer.FileSystem.FileExists("c:\temp\welcome.txt")) Then
  Console.WriteLine("File downloaded successfully")
  Console.WriteLine("Something went wrong")
 End If
 Catch ex As Exception
 End Try
End Sub
  • + Share This
  • 🔖 Save To Your Account