 |
|
 |
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.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
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; }
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Begin of uploaded file is truncated, if m_fResumeIfPossible is true and name of file starts with digits and file not exists in server folder.
Need to check result of FileSize() like following:
long lRemoteFileSize = 0; if( m_fResumeIfPossible ) { if (FTP_OK != FileSize(strRemoteFile, lRemoteFileSize)) lRemoteFileSize = 0; }
Also possible need fix FileSize() function to set lSize = 0 on error
PS: sorry for my bad English...
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
 |
Very nice. Thank you. most of the problems i had were with the windows data types (USHORT, DWORD, SOCKADDR, etc.). i created another header file "ftp.h" to hold the typedefs and a few other definitions. also had to change the calls to "select".
still need to write a program to test all the functions, but from what i have seen it seems to work quite well.
thank you. Charles Wright
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Hello
If you search a comfortable and reusable FTP client,
-- which is running on .NET Framework 1.1 or higher, -- which can automatically put together splitted files on the server, -- which allows to download only a part of a file on the server, -- which allows to resume any broken download, -- which automatically starts a separate thread, -- which can be aborted any time from your main thread, -- which supports UTF8 encoded filenames, -- which has a built-in download scheduler, -- which has a built-in bandwidth control, -- which has a built-in preview function for the download of movies, -- which automatically reconnects the server after an error has occurred, -- which displays download progress in percent and in bytes and the remaining time, -- which writes a detailed logging for all operations it does, -- which is based on Wininet.dll and has one workaround for each of the 4 known Wininet.dll bugs, -- which is very well tested and bug-free, -- which is written by a very experienced programmer and has a very clean and well documented sourcecode,
then have a look at this project:
ElmueSoft Partial FTP Downloader[^]
Elmü
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Apparently quite a few people have already tried to compile this with VC6 - but has anyone managed to compile this code without errors? What modifications are necessary and where? Please share any information that you may have. Thank you.
|
| Sign In·View Thread·PermaLink | 1.25/5 (4 votes) |
|
|
|
 |
|
 |
Hello,
I am also facing the problem, programming in VC6. As a matter of fact there are tons of ftpclient classes available but only the least work with c++ (without .net).
This class looks just perfect for my needs, unfortunately I cannot get it to work.
I get the following linker errors no matter what I try.
wnFTP.obj : error LNK2001: Nichtaufgeloestes externes Symbol "public: virtual __thiscall nsFTP::CFTPClient::~CFTPClient(void)" (??1CFTPClient@nsFTP@@UAE@XZ) ownFTPDlg.obj : error LNK2001: Nichtaufgeloestes externes Symbol "public: virtual __thiscall nsFTP::CFTPClient::~CFTPClient(void)" (??1CFTPClient@nsFTP@@UAE@XZ) ownFTPDlg.obj : error LNK2001: Nichtaufgeloestes externes Symbol "public: __thiscall nsFTP::CFTPClient::CFTPClient(class nsSocket::IBlockingSocket *,unsigned int,unsigned int,unsigned int)" (??0CFTPClient@nsFTP@@QAE@PAVIBlockingSocket@nsSocket@@III@ Z) ownFTPDlg.obj : error LNK2001: Nichtaufgeloestes externes Symbol "class nsSocket::IBlockingSocket * __cdecl nsSocket::CreateDefaultBlockingSocketInstance(void)" (?CreateDefaultBlockingSocketInstance@nsSocket@@YAPAVIBlockingSocket@1@XZ) Debug/ownFTP.exe : fatal error LNK1120: 3 unaufgeloeste externe Verweise
Nichtaufgeloestes externes Symbol should mean sth. like unreferenced external symbol
Can anyone help me?
I have tried to add the Ws2_32.lib to my project, also to include the winsock2.h and the windows.h in the stdafx.h, but it won't work.
These linker errors occur, no matter if the lib is included or the winsock2 is included or neither of them.
I am trying to build a mfc windows application. It is completely empty except the definition nsFTP::CFTPClient m_ftp; in the header.
Thanks in advance, Richard
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
 |
bool CFTPClient::ExecuteDatachannelCommand(const CDatachannelCmd& crDatachannelCmd, const tstring& strPath, const CRepresentation& representation, bool fPasv, DWORD dwByteOffset, ITransferNotification* pObserver) const { if( m_fTransferInProgress ) return false;
if( !IsConnected() ) return false;
// check representation if( m_apCurrentRepresentation.get()==NULL ) m_apCurrentRepresentation.reset(new CRepresentation(CType::ASCII())); if( representation!=*m_apCurrentRepresentation ) { // transmit representation to server if( RepresentationType(representation)!=FTP_OK ) return false; *m_apCurrentRepresentation = representation; }
std::auto_ptr apSckDataConnection(m_apSckControlConnection->CreateInstance()); if( fPasv ) { if( !OpenPassiveDataConnection(*apSckDataConnection, crDatachannelCmd, strPath, dwByteOffset) ) return false; } else { if( !OpenActiveDataConnection(*apSckDataConnection, crDatachannelCmd, strPath, dwByteOffset) ) return false; }
const bool fTransferOK = TransferData(crDatachannelCmd, pObserver, *apSckDataConnection); apSckDataConnection->Close();
// get response from ftp server CReply Reply; if( !fTransferOK || !GetResponse(Reply) || !Reply.Code().IsPositiveCompletionReply() ) return false;
return true; }
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
You are right. There is a bug in the CBlockingSocket class (see forum entry "Bug on connection break."). Add the following destructor to the file "BlockingSocket.cpp". CBlockingSocket::~CBlockingSocket() { Cleanup(); } After defining this destructor you can remove the line "apSckDataConnection->Close();" from ExecuteDatachannelCommand. The solution with the destructor is better than calling it directly.
|
| Sign In·View Thread·PermaLink | 3.50/5 (2 votes) |
|
|
|
 |
|
 |
I write two function ,in default use port mode. void ftptest() { nsFTP::CFTPClient ftpClient; nsFTP::CLogonInfo logonInfo;
logonInfo.SetHost(m_strFtpAddress.c_str(), m_iFtpPort, m_strFtpUserName.c_str(), m_strFtpPassword.c_str());
if (!ftpClient.Login(logonInfo)) { return ; }
nsFTP::TSpFTPFileStatusVector list; ftpClient.List("/", list);
for( nsFTP::TSpFTPFileStatusVector::iterator it=list.begin(); it!=list.end(); ++it ) { if( (*it)->IsCwdPossible() ) { if( !(*it)->IsDot() ) { std::string name = (*it)->Name().c_str(); printf("\n%s", name.c_str()); } } }
ftpClient.Logout(); } void test() { while(true) { ftptest(); } }
In the loop, the port is used by test one by one and no released, why? and how I can solve this problem?
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
I think it's the same problem as described in an earlier thread here. Add Cleanup to the destructor of CBlockingSocket. CBlockingSocket::~CBlockingSocket() { Cleanup(); }
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Can I use the library in my code and call it from another C++ code using the MFC class CInternetConnection? Is it fully supported? Thanks Triplebit
|
| Sign In·View Thread·PermaLink | 2.00/5 (1 vote) |
|
|
|
 |
|
 |
Hi,
> >if( !fTransferOK || !GetResponse(Reply) || !Reply.Code().IsPositiveCompletionReply() ) >
the above lines always return error after transferring multiple files.
Is this a problem in the program? or something else?
br,
|
| Sign In·View Thread·PermaLink | 2.00/5 (1 vote) |
|
|
|
 |
|
 |
Hello,I met a problem when i want to develop FTPClient with your FTPClass . A lot of warning about STL.I dont Know why,and when i use UploadFile,The program will be dead.When i tail the program ,It run to BOOL CBLockingSocket::Accept() { ... pConnect->m_hSocket = accept(m_hSocket, psa, &nLengthAddr); ..... } The program will be dead .Pls Help me~Thanks
Best Regards~
|
| Sign In·View Thread·PermaLink | 2.00/5 (1 vote) |
|
|
|
 |
|
 |
What compiler (development environment) do you use? - Microsoft (Visual Studio 6, 2003, 2005) - GNU compiler - or an other one What warnings do you get? What STL version do you use?
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
I use VS6.0, -The warnings are warning C4786 -one of my warning:
C:\Program Files\Microsoft Visual Studio\VC98\MFC\INCLUDE\afxcmn.inl(268) : warning C4786: 'std::_Treetification *>,std::allocator >::_Kfn,std::less,std::allocator >::const_iterator' : identifier was truncated to '255' characters in the debug information
-and STL is the default version when i install VS6.0.
The program can LogIn FTP ( which i have the popedom to upload and down load file),but i can not upload the file.
The code: ... if (ftpClient.UploadFile( "c:\\hehe.txt", "/ProjectDoing/Test/hehe3.txt" )) { box.MessageBox( " UpLoad Success! ", " hehe ", MB_OK ); } else { box.MessageBox( " UpLoad Fail! ", " hehe ", MB_OK ); }
... I found the uploading tread will be appended~ I dont know why ~
Best Regards~
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Using VS6.0 is the problem. Microsoft has made significant changes between the compiler in VS6.0 and VS2003. VS6.0 has a lot of deficits concerning to templates. The delivered STL implementation has changed in VS2003. As a result of this, there are compability problems between VS6.0 and VS2003. The source code have to be modified to run in VS6.0, but i don't have this version anymore.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
 |
One last hint: If your problem only exists in release mode (and not in debug mode) then try to disable the optimization in the release version. Sometimes the optimization leads to undesired effects. (You can also disable optimization with "#pragma" statements if you can localize the problem.)
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
 |
Hi,
CAN ANYONE PLEEEASE LEND A HAND ?
I've tried to use FTP Client Class in a .net 2005 c++ console application. I've added all the source files to the project. It compiles ok ... but I'm getting these linkage errors:
Linking... FTPClient.obj : error LNK2019: unresolved external symbol __imp__htonl@4 referenced in function "public: __thiscall nsSocket::CSockAddr::CSockAddr(unsigned long,unsigned short)" (??0CSockAddr@nsSocket@@QAE@KG@Z) FTPClient.obj : error LNK2019: unresolved external symbol __imp__htons@4 referenced in function "public: __thiscall nsSocket::CSockAddr::CSockAddr(unsigned long,unsigned short)" (??0CSockAddr@nsSocket@@QAE@KG@Z) FTPClient.obj : error LNK2019: unresolved external symbol __imp__inet_ntoa@4 referenced in function "public: class std::basic_string,class std::allocator > __thiscall nsSocket::CSockAddr::DottedDecimal(void)" (?DottedDecimal@CSockAddr@nsSocket@@QAE?AV?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@XZ) FTPClient.obj : error LNK2019: unresolved external symbol __imp__ntohs@4 referenced in function "public: unsigned short __thiscall nsSocket::CSockAddr::Port(void)const " (?Port@CSockAddr@nsSocket@@QBEGXZ)
|
| Sign In·View Thread·PermaLink | 1.00/5 (1 vote) |
|
|
|
 |
|
|
 |
|
 |
Yes I can.
That's mainly why I can't figure out the reason for a simple console application failing to link. It's almost a "hello world" console application. I include FTPClient.h in the main module, and at linkage, I get the error I posted earlier. I've figured out the symbols reported missing by the compiler belong to winsock2.h, which rules out errors in the source code.
I'm guessing it has something to do with build directives ...
Any light?
Thanks
|
| Sign In·View Thread·PermaLink | 2.00/5 (1 vote) |
|
|
|
 |