Click here to Skip to main content
11,930,048 members (50,466 online)
Click here to Skip to main content
Add your own
alternative version


24 bookmarked

Copy from FTP server to local Server through VB.Net

, 10 May 2007
Rate this:
Please Sign up or sign in to vote.
This code helps you to explain how to copy/downloads files from FTP server to local server


Just go through the code and you will come to know that how to copy or downloads the files from FTP server to your local server/machines by using VB.Net Code


Manuallyu copying the code from FTP server to local server is always a fun but the same is cumbersum job if gone through the code.........

Using the code

This is my one of the most beautiful work to copy multiple files from any FTP server to your desire folder or server........ Just go through the code and experience the beauty of it...

// Any source code blocks look like this
Dim oScript, oFileSys, objFSO, fileSearchObj, fileNameList, fileName, fileNameArray
Dim tempFileName As String

    '' set the FTP path and username/password fields

Dim ftp_address As String = "" '---> ftp site address
Dim ftp_username As String = "username" '---> user name 
Dim ftp_password As String = "passwd" '---> password

fileSearchObj = CreateObject("Scripting.FileSystemObject")
' Get all the files down loded to C:\ftpDownload folder
fileNameArray = fileSearchObj.GetFolder("C:\ftpDownload\")
fileNameList = fileNameArray.files

For Each fileName In fileNameList
    tempFileName =

    '1. Crate the temperory .ftp file (ftpCommand.ftp) which contain the FTP code 
    '2. Write the code for copying the file from FTP to Local folder
    '3. Write the code to delete the file from FTP after copy
    '4. Execute the file through command prompt

    Dim objTextFile
    Dim strFTPFileName As String = ""
    ' Step 1
    ' this file will be saved on the root folder (bydefault)
    strFTPFileName = "C:\ftpCommand.ftp"
    ' create the temporary on root folder 
    objTextFile = objFSO.CreateTextFile(strFTPFileName, True)
    ' Step 2
    ' write the ftp command line code to fetch files in the file test.ftp
    objTextFile.WriteLine("open " & ftp_address) '-------> open FTP site/location
    objTextFile.WriteLine(ftp_username) '--------------> ftp user name
    objTextFile.WriteLine(ftp_password) '--------------> ftp user password
    objTextFile.WriteLine("cd tempFolder") '-----------> cd tempFolder 
    ' tempFolder is the source folder on FTP site from where application will down load files
    ' Example- ftp:\\\tempFolder 
    objTextFile.WriteLine("lcd C:\ftpDownload") '--------> This is the working directory
    ' Step 3
    objTextFile.WriteLine("delete " & tempFileName) '----> delete 'filename' // to delete the same copied files from the FTP server
    objTextFile.WriteLine("y") '--------------> y //propmt message 'yes' to commit the copy operation
    objTextFile.WriteLine("bye") '--------------> bye //ftp command to come out of the ftp command promt
    ' close the stream for creating the new ftp file
    objTextFile = Nothing
    ' Step 4
    '----------------------------------------------------------- ' create the FTP command promt syntax to execute the files
    Dim strCMD As String
    strCMD = "ftp.exe -i -s: C:\ftpCommand.ftp"
    ' create the temperory file to store the output generated after executing the FTP command 
    Dim strTempFile As String
    strTempFile = "C:\ftpOutput.txt"
    ' call the command promt control to execute the delete operation
    Call oScript.Run("cmd.exe /c " & strCMD & " > " & strTempFile, 0, True)

Catch ex As Exception
    ' Some thing goes wrong
End Try 

<pre>You can use the desire desination folder instead of harc-coded C:\ drive


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Nakul Lande
Web Developer
United States United States
Optimistic....... and Looking forward

You may also be interested in...

Comments and Discussions really? Total waste of time Pin
Sabarinathan Ramachandran21-Jul-15 21:57
memberSabarinathan Ramachandran21-Jul-15 21:57 
BugSomething is wrong. Pin
Mshadow1717-Jun-14 17:03
memberMshadow1717-Jun-14 17:03 
QuestionGetting error on declaration Pin
Ronny George30-Jan-12 3:13
memberRonny George30-Jan-12 3:13 
GeneralHi Pin
prabupep29-Jul-10 1:58
memberprabupep29-Jul-10 1:58 
GeneralMy vote of 1 Pin
JBDJr28-May-09 11:19
memberJBDJr28-May-09 11:19 
GeneralWhere is the copy code Pin
navalArya22-Oct-07 14:16
membernavalArya22-Oct-07 14:16 
QuestionVBS!? Pin
T4Top10-May-07 3:21
memberT4Top10-May-07 3:21 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.151126.1 | Last Updated 10 May 2007
Article Copyright 2007 by Nakul Lande
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid