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" Try If (My.Computer.FileSystem.FileExists(filename)) Then My.Computer.FileSystem.DeleteFile(filename) 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") Else Console.WriteLine("Something went wrong") End If Catch ex As Exception Console.WriteLine(ex.Message) End Try Console.ReadLine() End Sub