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

Altaf PatniSoftware DeveloperAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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.
Altaf PatniSoftware DeveloperAuthor 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.
Altaf PatniSoftware DeveloperAuthor 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
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

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.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Altaf PatniSoftware DeveloperAuthor 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

Altaf PatniSoftware DeveloperAuthor Commented:
how to remove first line from text file
Altaf PatniSoftware DeveloperAuthor 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.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming Languages-Other

From novice to tech pro — start learning today.