How to Get file from server to client

Using Ftp Command in vb6.0 , I know how to PUT file from client to server, using attached Code.

Now i want to GET file from Server to Client using same attache code

Please assist me
Dim fs, f, f1, filelist()
Dim i As Integer, j As Integer
i = 0
ReDim filelist(0)

Set fs = CreateObject("Scripting.FileSystemObject")

Set f = fs.GetFolder("D:\MyFolder\MySecondFolder")

For Each f1 In f.Files

    If LCase(Right(f1.Name, 3)) = "csv" Then
        i = i + 1
        ReDim Preserve filelist(i)
        Set filelist(i) = f1
        GetAName1 = Split(f1, "\")(3)       '''removing all charactor which is before 3 "\"
            BName = Len(GetAName)           '''getting name length
            BName1 = Len(f1)                '''getting full file path length
            BName2 = BName1 - BName
            BName3 = Left(f1, BName2 - 1)   '''local file path
        LocalFile = Chr(34) & f1 & Chr(34)
        RemoteFile = Chr(34) & GetAName & Chr(34)
'        '''''connecting server
        Call myftpconn
'        ''''''''''''''''''''''
        Inet1.Execute , "PUT " & LocalFile & " " & RemoteFile
        While Inet1.StillExecuting
        Inet1.Execute , "CLOSE"

        Kill f1
    End If

Open in new window

Who is Participating?
Dont forget that some FTP servers can return a name-only list as a directory listing so you wouldn't need to create your own file.  Try sending the NLST protocol-level command and see what you get.  

Another possibility if you are looking for ways to do it with no money is to write a script for the DOS ftp client and launch that external ftp.exe from your code instead of using the Inet control.  If you can get that client's mget "*.*" command to work for you maybe you won't have to bother with the remote directory listing at all.
If you want to get all the files on the remote FTP server you'll need to first request a directory listing from the remote site.  Then you'll need to set up a loop that parses the directory listing and pulls out one filename on each loop iteration so that file can be downloaded.  

Some FTP servers are able to return just a list of file names without the modified date, file size, folders name, permissions, and so on so if your server can do this it makes parsing the directory listing a LOT easier.  The FTP standard does not specify the format of a directory listing so each type of FTP Server formats it a little different which can be a pain in the rear if you can't get a name-only list.

This could be a fun project if you are doing this for your own learning and development as a programmer but if somebody is paying you to do it as quickly as possible then you should consider recommending that they purchase a commercial FTP program with a COM interface that can be controlled by VB.  This way you can leave the directory parsing to the other program and just send commands that you want.  For example if you used Robo-FPT you would just need to send three commands:
FTPLOGON "" /user="MyUserName" /pw="SecretPassword"

The logic for parsing the remote directory structure and downloading each file is all wrapped up in that RCVFILE command so it is really easy.  The cost is $150 but this would probably pay for itself in your employer's eyes if it saves you one hour of development time (and it will.)  Another bonus is that if the format of the remote server's directory listing format ever changes you won't have to re-write your parsing code.  Commercial FTP cllients contain logic for parsing dozens of different formats so you don't have to re-invent the wheel.
crystal_TechAuthor Commented:
Thanks for reply

My employer is not going to buy third party software.

I know how to use FTP GET command,
But i am just looking for to get file ( only csv files ) list from specific directory in server
 i will get the file list or some kind of loop then
it will be easy for me to download files from server to client.
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

crystal_TechAuthor Commented:
Ok now i think i have something to share with experts
I am not sure it is a good way or not...!

The way i am thinking is
in the server have one listname.txt file and in this txt file have all files name which need to be download by client.
Client will download this txt file, after download this listname.txt, the client application will delete this listname.txt file from server.
then client application will pick the file name from list and run FTP GET Command,
after successfully download  file,
application will remove that file name from listname.txt and then delete that file from server also.
then check for next name in the namelist.txt and same process using loop

Part Include above method
1 - Creating name list in server
2 - download name list by client
3 - delete namelist.txt from server
4 - donwload files from server to client ( by client application )
5 - remove name in the name list by client
6 - delete files from server ( which is downloaded )
then check for next loop
crystal_TechAuthor Commented:
Thanks Alex

using "mdir" DOS ftp command getting list but not in desire formate, in the list getting date, time, size, and file name and also getting sub directory name.

But i need only file name.

Requirement is to successfully download files from server then delete those files,
so each and every time when a file download then delete it from server.

till date what i achieved is using inet control
1 - Creating name list in server
2 - download name list by client
3 - delete namelist.txt from server

I am up to get file according to namelist.txt through loop

crystal_TechAuthor Commented:
how to remove first line from text file
crystal_TechAuthor Commented:
ok i done it
All done, through inet, and file system object ( fso )

1 - Creating name list in server
2 - download name list by client
3 - delete namelist.txt from server
4 - donwload files from server to client ( by client application )
5 - remove name in the name list by client
6 - delete files from server ( which is downloaded )

Thanks Alex
You encourage me to complete this task

Congratulations!  You did it, but certainly not the easy way.

At first I was thinking how silly your employer must be to not spend the $150 for Robo-FTP and go with a three line solution:
RCVFILE "*" /delete

Upon reflection I can see two obvious advantages of doing it your way: 1) your code can now be installed on mulitple computers without incurring additional license fees and 2) this is an investment in YOUR skills as a solution provider... a training expense more valuable than a book or seminiar because it is real-world problem solving and actually solved an existing problem for your business rather than some contrived classroom demonstration.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.