A
hi!
ich hab mal den upload-teil wie folgt umgebaut
// --------------------------------------------------------------------------------------- upload
// open remote-ftp-file for uploading
// text output to application
CFTPmt::_fptr_appLoggerFnc( L"open remote-ftp-file for uploading: " + pUploadFileBin->wsRemoteFilename + L"\n" );
HINTERNET hOpenFile = FtpOpenFileW(
CFTPmt::_FTPConn.hConnect,
pUploadFileBin->wsRemoteFilename.c_str(),
GENERIC_WRITE,
FTP_TRANSFER_TYPE_BINARY|INTERNET_FLAG_RESYNCHRONIZE,
NULL
);
// exit thread if FtpOpenFileW fails
if( hOpenFile == NULL )
{
// text output to application
CFTPmt::_fptr_appLoggerFnc( L"Error opening remote file for upload: " + pUploadFileBin->wsLocalFilename + L"\n" );
pUploadFileBin->bError = TRUE;
// free memory
free (buffer_RAWData);
// call the 'thread-finished' function
CFTPmt::onUploadFile_Binaray( pUploadFileBin );
// end calling thread - doesn't close the thread handle
unsigned int retVal = 0;
_endthreadex( retVal );
return retVal;
}
// FtpOpenFileW result was ok
CFTPmt::_fptr_appLoggerFnc( L"FtpOpenFileW ok: \n" );
// progress upload
DWORD dwNumberOfBytesWritten = 0;
BOOL res;
int nChunkSize = 1024;
BOOL doProcess = TRUE;
std::wostringstream status;
UINT tryAgainTimes = 3;
BOOL waiting = FALSE;
while ( doProcess ) // dwNumberOfBytesWritten < sizeof(char)*lSize
{
if( !waiting )
{
res = InternetWriteFile(
hOpenFile,
buffer_RAWData,
nChunkSize, // sizeof(char)*lSize
&dwNumberOfBytesWritten
);
}
if ( !res )
{
// text output to application
status.str(L"");
status << L"Error uploading File: " << pUploadFileBin->wsLocalFilename << L"\n LAST ERROR: " << GetLastError() << L" - " << ( CFTPmt::getLastFTP_Response() ) << L" res = " << res << L"\n";
CFTPmt::_fptr_appLoggerFnc( status.str() );
if( GetLastError() == 997 && tryAgainTimes > 0 ) // 997 = asynchronous I/O operation is pending !?
{
waiting = TRUE;
status.str(L"");
status << L"waiting for server - will try again " << tryAgainTimes << L" times ...\n";
CFTPmt::_fptr_appLoggerFnc( status.str() );
tryAgainTimes --;
Sleep(1000);
}
else
{
// set error flag for user of this class
pUploadFileBin->bError = TRUE;
// call the 'thread-finished' function
CFTPmt::onUploadFile_Binaray( pUploadFileBin );
// end calling thread - doesn't close the thread handle
unsigned int retVal = 0;
_endthreadex( retVal );
return retVal;
}
}
else
{
status.str(L"");
status << ( dwNumberOfBytesWritten / 1024 ) << L" / " << ( sizeof(char)*lSize / 1024 ) << L" KB res=" << res << "\n";
CFTPmt::_fptr_appLoggerFnc( status.str() );
Sleep(1000);
buffer_RAWData += nChunkSize;
waiting = FALSE;
}
}
status.str(L"");
status << L"Uploading File OK. \n" << ( CFTPmt::getLastFTP_Response() ) << L"\n";
CFTPmt::_fptr_appLoggerFnc( status.str() );
nun gibt es 2 symptome die auftreten:
1.) am ftp-server existiert dieses file noch nicht dann lädt mein programm das file zwar im hintergrund hoch ( feststellbar im filezilla und F5 drücken ... )
meldet aber folgende fehler:
Connection to the FTP-Server established ...
APP: onOpenFTPConnection called in MAIN b=0
Preparing File for upload: D:\alexTestbilder.rar
filesize in kb: 17270
filesize in b: 17684836
memory alloc size: 17684836
Successfully read File: D:\alexTestbilder.rar
open remote-ftp-file for uploading: /httpdocs/picture_library/alexTestbilder.rar
FtpOpenFileW ok:
Error uploading File: D:\alexTestbilder.rar
LAST ERROR: 997 - ErrorId = 0 Error Message: res = 0
waiting for server - will try again 3 times ...
Error uploading File: D:\alexTestbilder.rar
LAST ERROR: 997 - ErrorId = 0 Error Message: res = 0
waiting for server - will try again 2 times ...
Error uploading File: D:\alexTestbilder.rar
LAST ERROR: 997 - ErrorId = 0 Error Message: res = 0
waiting for server - will try again 1 times ...
Error uploading File: D:\alexTestbilder.rar
LAST ERROR: 997 - ErrorId = 0 Error Message: res = 0
APP: onUploadFile_Binaray called in MAIN b=1
Connection to the FTP-Server closed ...
Connection to the Internet closed ...
danach ist die datei am server ca. 1MB gross.
wenn ich nun nochmal das programm starte, hängt es ca 1 minute beim aufruf von
FtpOpenFileW
und bricht dann mit meiner fehlermeldung
Error opening remote file for upload: D:\alexTestbilder.rar
ab. das file am server ist nun zwar da aber nur mehr 0kb gross.