|
Following is my code, it is really simple. Please correct me if I have something wrong.
void CFTPClient1Dlg::OnBnClickedButton1()
{
nsFTP::CFTPClient ftpClient(nsSocket::CreateDefaultBlockingSocketInstance(), 30);
nsFTP::CLogonInfo loginInfo;
loginInfo.SetHost(static_cast<lpctstr>(_T("192.168.1.10")), static_cast<ushort>(2211),
static_cast<lpctstr>(_T("user")), static_cast<lpctstr>(_T("passwd")),
static_cast<lpctstr>(_T("")));
bool hr = false;
hr = ftpClient.Login( loginInfo );
if ( hr )
{
MessageBox( L"Login Succeeded" );
}
else
{
MessageBox( L"Login Failed" );
return;
}
hr = ftpClient.UploadFile( _T("d:/video7.flv"), _T("1.flv") );
if ( hr )
{
MessageBox( L"Upload file succeeded" );
}
else
{
MessageBox( L"Upload file failed" );
}
}
The bug's repro step is as following:
1. Click the button, and now the file is being transfered.
2. Disable the network connection.
3. Upload file failed is shown.
4. Enable the network connection.
5. Click the button again.
Expect behavior:
1. Messagebox "Login Succeeded" shown.
2. File is transferred.
3. MessageBox "Upload file succeeded" shown.
Actual behavior:
1. Messagebox "Login Succeeded" shown.
2. Messagebox "Upload file failed" shown.
3. Netstat shows that every retry will leave a Listening port there, if you close the process, all opening port disapperred.
I have retried for 30 times, each of two have 30 seconds interval. It still does not working.
I tried to use command line ftp to connect the server and put a file, it works.
So I think there is something not cleared when the network is unpluged, am I right?
The internal error I receive is "Internal Error: Receive timeout error :\generalv\gvclient\generalv\ftpclient_demo\ftpclient.cpp:1,102 files.."
At the same time, by "net state /a" I found the listening port of my pc is become more and more.
Therefore, it is a resource leak? or I have some thing wrong in using it?
Thanks,
Mingju
-- modified at 4:44 Friday 15th June, 2007
|
|
|
|
|
You are right. There is a bug in the CBlockingSocket class. Add the following destructor to the file "BlockingSocket.cpp".
CBlockingSocket::~CBlockingSocket()<br />
{<br />
Cleanup();<br />
}<br />
|
|
|
|
|
Thanks man,
You are the one!
|
|
|
|
|
Hello!
Does anyone make a unix port of this nice class yet? I tried but failed. Would be nice if anyone has done and could provide it.
|
|
|
|
|
In the DevCPP project there is a wrong linker library added. The one in the current project is a library from Visual Studio. You should use the libws2_32.a from MinGW compiler if you use MinGW.
grtz
|
|
|
|
|
Too late reply, but may help some readers:
Open your project linker parameters and add following
-lwininet -lwsock32
and discard existing vc7 library name, I got it working this way.
regards
easy GUI building www.radcpp.com
|
|
|
|
|
I am using classes to implement blocking TCP/IP sockets in an existing MFC app.
Noticed that 'virtual void GetPeerAddr(LPSOCKADDR psa) const = 0;' is missing in declaration of class IBlockingSocket in BlockingSocket.h
Everything else is working great! thx
|
|
|
|
|
when i try to upload files to the server that does not sopport port 21,it doesn't work!
how can i do to solve this problem?thank you.
|
|
|
|
|
Following is an example that using port 1234.
nsFTP::CFTPClient ftpClient(nsSocket::CreateDefaultBlockingSocketInstance(), 30);
nsFTP::CLogonInfo loginInfo;
loginInfo.SetHost(static_cast<lpctstr>(_T("192.168.1.50")), static_cast<ushort>(1234),
static_cast<lpctstr>(_T("user")), static_cast<lpctstr>(_T("passwd")),
static_cast<lpctstr>(_T("")));
bool hr = false;
hr = ftpClient.Login( loginInfo );
if ( hr )
{
MessageBox( L"Login Succeeded" );
}
else
{
MessageBox( L"Login Failed" );
}
if ( hr )
{
hr = ftpClient.UploadFile( _T("d:/ff.txt"), _T("2.txt") );
}
|
|
|
|
|
Hi all,
I use VS 6.0 Enterprise and got follow warnings and errors during compile FTPClient.cpp
Warning (112):
Compiler Warning (level 1) C4786
'identifier' : identifier was truncated to 'number' characters in the debug information
Error (abort compile) - I think thats a result from warnings.
Fatal Error C1063
compiler limit : compiler stack overflow
I don't know what can I do now. Need a hot tip.
Thanks for help.
Guru
|
|
|
|
|
hi! My name is JC im from Puerto Rico. Right now my C++ knowledge is a bit "limited"
and Im developing an application tthat will end up updating a txt file in an FTP. Your class got the perfect functions i need. Exactly what i need for my progrm to work is this:
nsFTP::CFTPClient ftpClient;
nsFTP::CLogonInfo logonInfo("localhost", 21, "anonymous",
"anonymous@user.com");
// connect to server
ftpClient.Login(logonInfo);
// do file operations
ftpClient.DownloadFile("/pub/test.txt", "c:\\temp\\test.txt");
ftpClient.UploadFile("c:\\temp\\test.txt", "/upload/test.txt");
// disconnect
ftpClient.Logout();
dat is basically all i need BUT your work is very hard to understand for me and i just dont know WHAT to include and where to include.. Id appreciate any help you can give me. Thanks in advance
-JC
|
|
|
|
|
can anyone give me the approach to download a file from a ftp server using multithreding. (i.e. separate threads for downloading simultaneously USING JAVA)
VIVEK
lathi
|
|
|
|
|
I have compiled your FTP Client Class successfully with msvc6.0,and it works wonderfully. Good work!
but I need to support IPv6 about this Class,can you suggest me something about this?
|
|
|
|
|
I have noticed that if the connection is lost during the upload process, instead of giving a time out message or any other appropriate error, the application will simply crash.
Do you recommend a course of action for more appropriately handling this problem?
-Mike
|
|
|
|
|
I have tried to reproduce the error but the application never crashes (one time the ftp-server crashed). I have tried it several times. The client always displayed an error message (e.g. timeout). Can you reproduce the error on your machine?
To which server have you connected? Is it a public server (so I can connect to it)?
Can you mail me a screenshot of the call stack?
|
|
|
|
|
I get some redefinitions and missings. After the next includes in Definements.h it works:
#include <time.h>
#include <assert.h>
Best regards
Stephan
|
|
|
|
|
Hello,
I created a new console project with VC7 and added the sources from the console example project.
Trying to compile, the compiler throws a lot of redefinition errors, something like:
c:\Program Files\Microsoft Visual Studio .NET
2003\Vc7\PlatformSDK\Include\WinSock2.h(2233) : error C2375: 'WSAStartup': redefinition; different basic types
c:\Program Files\Microsoft Visual Studio .NET
2003\Vc7\PlatformSDK\Include\WinSock2.h(2268) : error C2375: 'WSASetLastError': redefinition; different basic types
etc.
Who knows what I did wrong and how can I solve this problem.
Thanks for your help,
regards,
mvp
|
|
|
|
|
can anybody tell me?
anyway, thanks.
|
|
|
|
|
Resuming is enabled by default. With SetResumeMode you can turn on/off resuming. If resuming is enabled, then there will be a lookup if the target file exists. If it exists then the new offset will be set with Restart method and only the remaining bytes will be downloaded and added to the target file.
|
|
|
|
|
It is me again.
I had waited this new version with big interest.
Some features are very useful, such a new form of listeners(CNotification) and many other ...
I have ideas, which can make your class more powerful.
1) I think that 32-bit size variable lReceivedBytes must be in CNotification.
at now file with size more 4 GB are wide-spread (DVD iso for example ... ).
2) Class is designed for multi-thread enviroment, but does not use this power completely.
I think that threads-pool technology will apropos in this case.
Creating some one class "FTPPool" can make your component best,than others.
Enjoy you.
|
|
|
|
|
I don't know how to upload files?
Could anyone help me?
give me some steps, please.
thomas
-- modified at 5:22 Friday 2nd December, 2005
|
|
|
|
|
Has anyone else experienced memory leaks with FTPClient? I am using Visual C++ 6.0 and after making various modifications to get the library to compile I have a simple test app which just prints out the files from an FTP site onto the screen. In debug mode, VC 6.0 displays the following dump:
<br />
Detected memory leaks!<br />
Dumping objects -><br />
{874} normal block at 0x00D87F50, 1056 bytes long.<br />
Data: < [B > 20 00 00 00 00 00 00 00 B0 5B 42 00 00 00 00 00 <br />
sockcore.cpp(87) : {82} client block at 0x00DA2DE0, subtype 0, 28 bytes long.<br />
a CPtrList object at $00DA2DE0, 28 bytes long<br />
sockcore.cpp(85) : {81} client block at 0x00DA1070, subtype 0, 28 bytes long.<br />
a CMapPtrToPtr object at $00DA1070, 28 bytes long<br />
sockcore.cpp(83) : {80} client block at 0x00DA10C0, subtype 0, 28 bytes long.<br />
a CMapPtrToPtr object at $00DA10C0, 28 bytes long<br />
{78} normal block at 0x00DA1230, 12 bytes long.<br />
Data: < (Z > 9C 28 5A 00 CD CD CD CD 00 00 00 00 <br />
Object dump complete.<br />
The leak seems to be in AfxSocketInit()! (I used Code Projects "leakfinder" to find that out)
Is this because AfxSocketInit() is expected to be called from CWinApp::InitInstance() maybe?
I don't have a clue what's going on! I come from a Unix background where things just work.
Cheers,
Paul Drummond
|
|
|
|
|
These memory leaks are all from MFC-classes. The CFTPClient class and all appendant classes don't use any MFC class. The error must be outside this code.
|
|
|
|
|
Hello,
I use Visual C++ 6.0, too.
I have done several modification to get it to compile,
but I have given up with the error
C:\Programme\VisualStudio\VC98\INCLUDE\iterator(82) : error C2039: 'push_back' : Ist kein Element von 'basic_string<char,struct std::char_traits<char="">,class std::allocator<char> >'
(push_back is not an element of ...)
Maybe you can help me or send me your successful port to Visual C++ 6.0 ?
Thanks and kind regards,
Martin
|
|
|
|
|
You can update your STL from www.stlport.org and rebuild it.
|
|
|
|