|
Sorry, I have removed the console example from the latest revision. You may download the previous revision.
|
|
|
|
|
where could i find the former version which contain console example ?
as a flesh programmer , MFC demo is a little bit complicated for me .
the base need for the class is to connect the server , and then upload and download a file .
the console demo would be easier for flesh programmer to acquire .
|
|
|
|
|
|
changes in gcc 4.7. require unistd.h to be included. In BlockingSocket.h line number 34
#elif defined(unix)
#include <sys/socket.h>
#include <unistd.h>
#include <arpa/inet.h> // needed for inet_ntoa and inet_addr
#include <netdb.h> // needed for gethostbyname and gethostbyaddr
#include <errno.h>
#include <stddef.h>
#endif
|
|
|
|
|
Needed to be able to sync an ftp folder to a local folder and your code worked right out of the box
Well written ( unlike my spaghetti code ) and no bugs that I can see
Thank you for posting the code and spending the time to document
|
|
|
|
|
if compiled with -std=c++0x (c++11), you have a warning:
FTPClient.cpp:313:78: warning: 'auto_ptr' is deprecated
and an error:
BlockingSocket.cpp need: #include stddef.h for ptrdiff_t (line 407)
|
|
|
|
|
how to use this class when I want to upload large file which than 4GB,
thanks
yes
|
|
|
|
|
This is a great inspiring article. I am pretty much pleased with your good work. You put really very helpful information. Keep it up once again.
|
|
|
|
|
thanks a lot for this great article !
|
|
|
|
|
hi, i found a problem when i use the code as follow
nsFTP::CFTPClient m_LocalFTPClient;
nsFTP::CLogonInfo LogonInfo;
if (!m_LocalFTPClient.IsConnected())
{
LogonInfo.SetHost(szSVRIP, 21, szUserName, szPassWD, static_cast<LPCTSTR>(""));
if (m_LocalFTPClient.Login(LogonInfo))
{
nsFTP::TSpFTPFileStatusVector list;
m_LocalFTPClient.List("/", list);
}
}
when i comment out "m_LocalFTPClient.List("/", list);" there is no resource leak,otherwise
the process's memory is increased by 4k once the code is invoked, could anyone come aross
this problem?
|
|
|
|
|
because it was intercepted by your firewall. go to set the firewall allow the connect.
|
|
|
|
|
how to download all files with filename matching using c++ from an ftp server
thanks
|
|
|
|
|
In method
int CFTPClient::FileModificationTime(const tstring& strPath, tstring& strModificationTime) const
Change line 1676 (iPos > -1) to the below
if( iPos != tstring::npos ) // instead of (iPos > -1)
Leaving to (iPos > -1) is not working properly with the compiler I use, it always fails. Since -1 for unsigned is also the biggest possible number.
|
|
|
|
|
In BlockingSocket.cpp function
void CBlockingSocket::Create(int nType /* = SOCK_STREAM */)
Had to change
if( (m_hSocket=socket(AF_INET, nType, 0)
to
if( (m_hSocket=socket(AF_INET, nType, IPPROTO_TCP)
Otherwise the socket never received a response.
|
|
|
|
|
Hello.
I can't compile the code.
I'm getting those errors.
Cannot open include file: stdafx.h
This error occures in those files:
BlockingSocket.cpp line 8
FTPClient.cpp line 49
FTPDataTypes line 16
FTPFIleState.cpp line 16
FTPListPare line 29
|
|
|
|
|
The stdafx.h/stdafx.cpp files are Microsoft specific extensions.
You need to open FTPexample.sln using Microsoft Visual Studio in order to build the project without code changes.
If you use another compiler and linker (like gcc) then you need to port the code for your environment.
Please google "porting Visual Studio projects to XYZ....".
|
|
|
|
|
Hi otom,
I try to retrieve all folders and files on the ftp-server and an instance of CFTPClient runs in a thread. but i get always a problem when excuting List(), just like this:
nsFTP::TSpFTPFileStatusVector list;
if (!client.List(url.toStdWString(), list)) { .... }
so the thread is blocked... as i debugged, i saw that occurred in the function
CFTPClient::OpenActiveDataConnection(...) {
...
if( !apSckServer->Accept(sckDataConnection, sockAddrTemp) ) {
...
}
and in the function
bool CBlockingSocket::Accept(...) {
...
pConnect->m_hSocket = accept(m_hSocket, psa, &nLengthAddr);
...
}
Calling of accept(m_hSocket, psa, &nLengthAddr) returns never!
this phenomenon occurs at some subfolders on the server that i have access to them.
any idea? thank you
aurora
|
|
|
|
|
Have you more than one CFTPClient connection to the server open? The list command opens a data connection on the server. Sometimes servers do not allow to open more than one data connection from a client at the same time.
Maybe there is a bug in the posted version. I am going to release a new version soon.
|
|
|
|
|
Thank you Otom
Danke!
No. there is only one CFTPClient running. here is my code, very sample:
#include "stdafx.h"
#include "cstring"
typedef struct node_s {
std::wstring name;
std::wstring path;
int state;
} node_t;
bool itr_url(nsFTP::CFTPClient& client, const node_t& node)
{
if (node.name.empty()) {
return false;
}
nsFTP::TSpFTPFileStatusVector list;
if (!client.List(node.path, list)) {
return false;
}
printf("scanning %ls \n", node.name.c_str());
for(nsFTP::TSpFTPFileStatusVector::iterator it = list.begin();
it != list.end(); ++it) {
if ((*it)->IsCwdPossible()) { //this is a folder
node_t n;
n.name = (*it)->Name().c_str();
n.path = node.path + _T("/") + n.name;
n.state = 0;
if (!itr_url(client, n)) return false;
}
}
return true;
}
bool itr_url(nsFTP::CFTPClient& client, const std::wstring path)
{
nsFTP::TSpFTPFileStatusVector list;
if (!client.List(path, list)) return false;
printf("scanning %ls \n", path.c_str());
for(nsFTP::TSpFTPFileStatusVector::iterator it = list.begin();
it != list.end(); ++it) {
if ((*it)->IsCwdPossible()) { //this is a folder
node_t n;
n.name = (*it)->Name().c_str();
n.path = path + _T("/") + n.name;
n.state = 0;
if (!itr_url(client, n)) { return false; }
}
}
if (client.IsConnected()) client.Logout();
return true;
}
int _tmain(int argc, _TCHAR* argv[])
{
int port_number = 21;
nsFTP::CFTPClient ftpClient;
nsFTP::CLogonInfo logonInfo(_T("214.25.77.227"), 21,
_T("test"), _T("Q+683bjM"));
// Initialize use of Winsock DLL by a process
WORD wVersionRequested;
WSADATA wsaData;
int err;
wVersionRequested = MAKEWORD(2, 2);
err = WSAStartup(wVersionRequested, &wsaData);
if (err != 0) {
printf("WSAStartup failed with error: %d\n", err);
return 1;
}
if (LOBYTE(wsaData.wVersion) != 2 ||
HIBYTE(wsaData.wVersion) != 2) {
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");
ftpClient.Login(logonInfo);
itr_url(ftpClient, _T("./content"));
ftpClient.Logout();
WSACleanup();
return 0;
}
if you have many subfolders/files under ./content, you can see that it not work.
and you can also see that the processing of List() becomes very slow before it blocked...
could you help me?
Aurora
modified 23-Dec-11 13:02pm.
|
|
|
|
|
Hi otom,
Firstly, thanks for this code sample, it is very clean and mostly works perfectly.
However, I think I have seen the same problem that is reported here, namely, the ::List() operation blocks forever.
I was wondering if you have seen this, or whether you have made any changes that might fix this in V2.0?
Thank you again,
Ben
|
|
|
|
|
I got the FTPClient Code compiled for Linux, but first it didn't work. The problem was,
that for some select() calls in the code, the first parameter nfds was set to 0. This doesn't
matter under Windows, because this parameter is ignored.
Under Linux, the first parameter in select() must be set to the highest file descriptor + 1
Regards,
KH
|
|
|
|
|
Hi,
I'm testing your demo project, but when I run it, I don't obtain the logging response. Using a break point in function
void CFTPProtocolOutput::OnResponse(const tstring& strResponse)
on first line, the execution of the application is not stopped. Of course response string is not logging.
Can you help me to understand why this event occurred?
10x
===============================================================
Ok,
I found the solution to what was previously reported.
In the example you have made
void CFTPProtocolOutput: OnResponse (const & tstring strResponse)
but evidently, after this, you have modified the parent object
and then you must override
void CFTPProtocolOutput: OnResponse (const CReply & reply)
and working properly.
Because I have written, I must point out that in the function
void CFTPProtocolOutput: OnSendCommand (const tstring & strCommand)
you have entered the instruction
if (strCommand.length ()> 4 & & strCommand.substr (5) == _T ("PASS"))
but, at least with VS2008, this does not work. I corrected it in
if (strCommand.length ()> 4 & & strCommand.substr (0, 5) == _T ("PASS"))
and it's work fine.
Excellent work,
10x
Sandro
modified 20-Dec-11 8:48am.
|
|
|
|
|
Hi,
I'll want to know what's kind of licence is applied to this project. Can I use it for free in commercial and/or open source code?
10x
Sandro
Sandro
|
|
|
|
|
yes, you can use it in commercial applications; i have set the license to "The Code Project Open License (CPOL)"
|
|
|
|
|
Hello Sir,
I am using your source code in my project & Its working fine. But I have one problem I could not find the size of file which is on server(Linux). I am getting following message.
550 SIZE not allowed in ASCII mode
Could please provide solution to calculate size of file.
Regards,
Savio
|
|
|
|