|
|
Comments and Discussions
|
|
 |

|
Nice! Just in case anyone needs... To run the simple example from the article I had to:
- #include <ctime> and #include <cassert> in Definements.h.
- Add Ws2_32.lib to the linker dependencies (this is already mentioned in another post).
- Call WSAStartup.
|
|
|
|

|
Many thanks to Leandro for his insights into initializing the use of Winsock, and for his other hints.
What is needed for the raw source zip is an example main. Here is one based on Leandro's advice, MSDN documentation for WSAStartup, and the example code given in the original posting.
When populated with my account particulars, this code lists the destination directory. (Sorry but this post has all its indentations removed.)
// FTP_Test.cpp : Defines the entry point for the console application.
//
#include
#include
#include "FTPClient.h"
int _tmain(int argc, _TCHAR* argv[])
{
int port_number = 21;
nsFTP::CFTPClient ftpClient;
nsFTP::CLogonInfo logonInfo(_T(""), port_number,
_T(""), _T(""));
// Initialize use of Winsock DLL by a process
WORD wVersionRequested;
WSADATA wsaData;
int err;
/* Use the MAKEWORD(lowbyte, highbyte) macro declared in Windef.h */
wVersionRequested = MAKEWORD(2, 2);
err = WSAStartup(wVersionRequested, &wsaData);
if (err != 0) {
/* Tell the user that we could not find a usable Winsock DLL. */
printf("WSAStartup failed with error: %d\n", err);
return 1;
}
/* Confirm that the WinSock DLL supports 2.2.*/
/* Note that if the DLL supports versions greater */
/* than 2.2 in addition to 2.2, it will still return */
/* 2.2 in wVersion since that is the version we */
/* requested. */
if (LOBYTE(wsaData.wVersion) != 2 || HIBYTE(wsaData.wVersion) != 2) {
/* Tell the user that we could not find a usable */
/* WinSock DLL. */
printf("Could not find a usable version of Winsock.dll\n");
WSACleanup();
return 1;
}
else printf("The Winsock 2.2 dll was found okay\n");
/* The Winsock DLL is acceptable. Proceed to use it. */
/* Add network programming using Winsock here */
// In our case, do the ftp work
// connect to server
ftpClient.Login(logonInfo);
// get directory listing
nsFTP::TSpFTPFileStatusVector list;
ftpClient.List(_T("/"), list);
// iterate listing
for( nsFTP::TSpFTPFileStatusVector::iterator it=list.begin();
it!=list.end(); ++it )
printf("\n%s", (*it)->Name().c_str());
// do file operations
//ftpClient.DownloadFile(_T("/pub/test.txt"),
_T("c:\\temp\\test.txt"));
//ftpClient.UploadFile(_T("c:\\temp\\test.txt"),
_T("/upload/test.txt"));
//ftpClient.Delete(_T("/upload/NewName.txt"));
// disconnect
ftpClient.Logout();
/* Call WSACleanup when done using the Winsock dll */
WSACleanup();
// Finished
return 0;
}
|
|
|
|
 |
|
|
General News Suggestion Question Bug Answer Joke Rant Admin
|
A non-MFC class to encapsulate the FTP protocol.
| Type | Article |
| Licence | CPOL |
| First Posted | 27 Oct 2004 |
| Views | 268,473 |
| Downloads | 22,648 |
| Bookmarked | 181 times |
|
|