开发者

How to get directories,subdirectories, files creation date & time from FTP remote Server in C++?

开发者 https://www.devze.com 2023-01-12 23:51 出处:网络
How toget directories,subdirectories, files creation date & time from FTP 开发者_运维技巧remote Server in C++ ?

How to get directories,subdirectories, files creation date & time from FTP 开发者_运维技巧remote Server in C++ ? I want to create a FTP client in C++


CIt doesn't matter the language, Once you are connected to the ftp server, just send the commands following the FTP protocol..

You should check the File Transfer Protocol RFC

That is if you want to do an ftp client from scratch. You can use libraries for doing so.

The commands you need, could be LIST command. But It is crappy. A new RFC updates the first one and add two new commands that do exactly what you want. Those commands are MLST and MLSD and you can see the RFC 3659 here. You should take care, I think not all ftp servers accept these commands.

One think you can do, is use a sniffer like Wireshark to sniff and get info about what commands are used by FTP clients. (BTW: Wireshark filters should be: ftp || ftp-data )

Linux FTP Command uses LIST for its dir command.


There are two aspects to it... first you need to select some C++ (or C) socket functions to use to make the connection, then you need to implement the expect send/receive protocol involved with FTP to request and retrieve the directory and file content you're interested in. (In practice, though you haven't mentioned it, you're probably also interested in writing the retrieved data out somewhere in your own system).

There are many choices re the socket implementation... you can use the BSD socket API or find some precanned C++ API. How you implement it, or which library might do it well for you, depends greatly on your client architecture: whether it's single- or multi-threaded, retrieving one file at a time or downloading hundreds in parallel.

For FTP, the RFC document specifying the exchange protocol can easily be found searching the 'net, but will be considerable work to implement well from scratch.

Alternatively, you can find a library that already implements the FTP protocol, and wrap it into an application. It's not clear from your question exactly what you consider to be "creating a client", so this may or may not count.

Of course, there are dozens of simple ftp clients you could download for sample code, especially if you count C implementations that would build and can be customised in C++.


Libcurl is very useful for this sort of thing:

http://curl.haxx.se/libcurl/

0

精彩评论

暂无评论...
验证码 换一张
取 消