For my voice mail / Caller-ID function I placed the name / number of the person in a database but also I have the name of my contact (joe.png, luis,jpg etc), After Ive retrieved the information, I FTP back to the server to grab the image file

Here is how its done.

For the example;

FTP server is at

username is :webuser
password is :password
File to get: <variable called ImageName> in a folder called Images
Location to save: c:\images\<ImageName>
The default folder on my server have a folder called images/

On the server im running FileZilla FTP Server (Free)


Imports System.Net
Imports System.Net.Sockets
Imports System.IO
Public Function GetFTP(ByVal ImageName As String)
        Dim localFile As String = "c:\images\" + ImageName
        Dim remoteFile As String = "/images/" + ImageName
        Dim host As String = ""
        Dim username As String = "webuser"
        Dim password As String = "password"
           '1. Create a request: must be in ftp://hostname format, 
            Dim URI As String = host & remoteFile
            Dim ftp As System.Net.FtpWebRequest = _
            CType(FtpWebRequest.Create(URI), FtpWebRequest)

            '2. Set credentials
            ftp.Credentials = New _
            System.Net.NetworkCredential(username, password)
            '3. Settings and action

            ftp.KeepAlive = False

            'we want a binary transfer, not textual data
            ftp.UseBinary = True

            'Define the action required (in this case, download a file)
            ftp.UsePassive = False
            ftp.Method = System.Net.WebRequestMethods.Ftp.DownloadFile
           'Loop to read & write to file

            Using response As System.Net.FtpWebResponse = CType(ftp.GetResponse, System.Net.FtpWebResponse)
                     '-----Setup Response stream to grab the FileStream aka Data and send it to a file using the FileStream object.
                Using responseStream As IO.Stream = response.GetResponseStream                         
                    Using fs As New IO.FileStream(localFile, IO.FileMode.Create)
                        Dim buffer(2047) As Byte
                        Dim read As Integer = 0
                        '-----Once Data is detected in the ResponseStream Loop until empty,
                            read = responseStream.Read(buffer, 0, buffer.Length)
                            fs.Write(buffer, 0, read) '----- Write the 'read' variable into the file
                        Loop Until read = 0 

                    End Using
                End Using
            End Using

Exit function


  1. Hi,
    I’m trying to make FTP console APPS and your code is a good reference. But some of the code is truncated on the right margins!!


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s