Back to the WFC main page
CFileTransferProtocol
$Revision: 14 $
Description
This class simplifies FTP. It solves the problem of getting a single
file or a directory listing from an FTP server.
Constructors
- CFileTransferProtocol( LPCTSTR user_name = NULL, LPCTSTR password = NULL )
-
Constructs the object. If
user_name
is NULL, "anonymous"
will be used instead. If password
is NULL, an e-mail address
will be created using the current user
name (retrieved via GetUsername()) and the dotted IP address
(retrieved via CSimpleSocket::GetMyAddress())
of the computer. For example, if your user name is "Bob" and
your IP address is 1.2.3.4, the default password will be
"Bob@1.2.3.4".
Methods
void GetDirectory( const CUniformResourceLocator& url, CStringArray& directory )
-
Retrieves the directory listing from the URL given. For example,
"ftp://ftp.microsoft.com/bussys"
void GetFile( const CUniformResourceLocator& url, CByteArray& file_contents )
-
Retrieves the file specified in
url
and puts it into file_contents
.
void GetPassword( CString& password ) const
-
Retrieves the password to be used to log in to the ftp servers.
void GetUserName( CString& user_name ) const
-
Retrieves the login ID to be used when logging in to ftp servers.
BOOL PutFile( const CUniformResourceLocator& url, const CByteArray& file_contents )
-
Sends the contents of
file_contents
to the ftp server specified in url
.
It will return TRUE if the contents were sent, FALSE if it didn't.
void SetPassword( const CString& password )
-
Sets the password to be used to log in to the ftp servers.
void SetUserName( const CString& user_name )
-
Sets the login ID to be used when logging in to ftp servers.
Example
#include <wfc.h>
void test_CFileTransferProtocol( void )
{
WFCTRACEINIT( TEXT( "test_CFileTransferProtocol()" ) );
CFileTransferProtocol ftp;
CStringArray directory;
CUniformResourceLocator url( TEXT( "ftp://ftp.microsoft.com/" ) );
ftp.GetDirectory( url, directory );
_tprintf( TEXT( "Directory for %s\n" ), (LPCTSTR) url );
int index = 0;
while( index < directory.GetSize() )
{
WFCTRACE( directory.GetAt( index ) );
_tprintf( TEXT( "%s\n" ), (LPCTSTR) directory.GetAt( index ) );
index++;
}
CByteArray file_contents;
url = TEXT( "ftp://ftp.microsoft.com/disclaimer.txt" );
ftp.GetFile( url, file_contents );
_tprintf( TEXT( "Retrieved %d bytes\n" ), (int) file_contents.GetSize() );
}
Copyright, 2000, Samuel R. Blackburn
$Workfile: CFileTransferProtocol.cpp $
$Modtime: 1/04/00 5:15a $