cURL / Mailing Lists / curl-library / Single Mail

curl-library

Access violation error while doing ftp transfer using SSH protocol.

From: jitendra patil <jitendrapatil2000_at_gmail.com>
Date: Fri, 23 Jan 2015 17:48:52 +0530

Hello,

We are using LIBCURL 7.34.0 library for implementation of SFTP and FTPS.
But we are facing following issue when we run this in our production
environments, approximately we are trying to send more than 1 lakh files to
ftp server (Using WS_FTP 7.3.0 server with SSH enabled).

1) ERROR Access Violation Caught, error message: The thread attempted
to read from or write to a virtual address for which it does not have the
appropriate access (SSHFTPWorker.cpp:213)

ERROR Stack Trace: LIBEAY32.dll : at SHA512() in :line 0

LIBEAY32.dll : at SHA512() in :line 0

LIBEAY32.dll : at SHA1_Update() in :line 0

LIBEAY32.dll : at RAND_SSLeay() in :line 0

LIBEAY32.dll : at RAND_SSLeay() in :line 0

Address = 0x66b370 (SSHFTPWorker.cpp:213)

2) ERROR Access Violation Caught, error message: The thread attempted
to read from or write to a virtual address for which it does not have the
appropriate access(SSHFTPWorker.cpp:243)

ERROR Stack Trace: MSVCR110.dll : at wcsnlen() in :line 0

libssh2.dll : at libssh2_userauth_keyboard_interactive_ex() in :line 0

libssh2.dll : at libssh2_channel_read_ex() in :line 0

Address = 0x6f94e427 (SSHFTPWorker.cpp:243)

When this first exception occurs, we are using curl_easy_cleanup() function
to close the connection. Sometimes we are able to close the connection, but
sometimes when we using cleanup call it throws second exception. Because of
that session is remains in active at ftp server and that file is lock at
server side. And only after that session timeout we are able to send that
file, meanwhile when we trying to send same file we got curl error code as
79 and error at server side is "The process cannot access the file because
it is being used by another process."

Below are the our implementation,

bool CSSHFTPWorker::SendFile(std::tstring strLocalDir, std::tstring
strLocalFileName, std::tstring strRemoteDir, std::tstring strremoteFileName)

{

                bool retVal =false;

                HANDLE hFile = NULL;

                try

                {

                                CURLcode ccCurlResult = CURL_LAST;

                                curl_off_t cotFileSize;

                                LARGE_INTEGER liFileSize;

                                strLocalDir += _T("\\");

                                strLocalDir += strLocalFileName;

                                strRemoteDir += _T("/");

                                strRemoteDir += strremoteFileName;

                                hFile =
CreateFileA(strLocalDir.c_str(),GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
// Full path of file

                                if(hFile != INVALID_HANDLE_VALUE)

                                {

                                                if(m_lFileSize==0)

                                                {

GetFileSizeEx(hFile, &liFileSize);

                                                                cotFileSize
= liFileSize.QuadPart;

                                                }

                                                else

cotFileSize=m_lFileSize;

                                                                hCurl =
curl_easy_init();

                                                                if(hCurl)

{

curl_easy_setopt( hCurl, CURLOPT_PROTOCOLS, CURLPROTO_SFTP);

curl_easy_setopt(hCurl,CURLOPT_SSH_AUTH_TYPES,CURLSSH_AUTH_PASSWORD);

curl_easy_setopt(hCurl, CURLOPT_UPLOAD,
TRUE);

curl_easy_setopt(hCurl, CURLOPT_READDATA, hFile);

curl_easy_setopt(hCurl, CURLOPT_INFILESIZE_LARGE,cotFileSize);

curl_easy_setopt(hCurl,
CURLOPT_READFUNCTION,libcurl_read_callback);

curl_easy_setopt(hCurl, CURLOPT_NOPROGRESS, FALSE);

curl_easy_setopt(hCurl,
CURLOPT_PROGRESSFUNCTION,libcurl_progress_callback);

curl_easy_setopt(hCurl,
CURLOPT_PROGRESSDATA,m_pFTPProgressInfo);

strURL = _T("sftp://");

strURL +=structSSHFtpobj.strHostName;

strURL +=_T("/");

strURL +=strRemoteDir;

curl_easy_setopt(hCurl, CURLOPT_URL,
strURL.c_str());

curl_easy_setopt(hCurl,
CURLOPT_USERNAME,structSSHFtpobj.strUserName.c_str());

curl_easy_setopt(hCurl,
CURLOPT_PASSWORD,structSSHFtpobj.strPassword.c_str());

curl_easy_setopt(hCurl, CURLOPT_PORT,SSHPORT);

curl_easy_setopt(hCurl, CURLOPT_CONNECTTIMEOUT,m_FTPTimeOut);

ccCurlResult = curl_easy_perform(hCurl);

if (ccCurlResult == CURLE_OK)

{

retVal = true;

}

else

{

//Error

retVal = false;

std::tstring strMsg;

GetCurlError(ccCurlResult, strMsg);

NCRTRACE1(TRACE_TYPE_ERROR,"CSSHFTPWorker::SendFile(), curl_easy_perform()
API function failed while file sending. Error Code : %d",ccCurlResult);

m_ErrorMsg = _T(" Error Desc :") + strMsg;

}

curl_easy_cleanup(hCurl);

                                                                }

                                                                else

                                                                {

//Error

retVal = false;

std::tstring strMsg;

GetCurlError(ccCurlResult, strMsg);

m_ErrorMsg = _T(" Error Desc :") + strMsg;

                                                                }

                                                CloseHandle(hFile);

                                }

                                else

                                {

                                                //Error

                                                retVal = false;

                                }

                }

                catch(NCRException &ex)

                {

                                LOG_NCR_EXCEPTION(TRACE_TYPE_ERROR, ex);

                                doCurlCleanup();

                                if(hFile != NULL)

CloseHandle(hFile);

                                retVal = false;

                }

                return retVal;

}

void CSSHFTPWorker::doCurlCleanup()

{

                try

                {

                                if(hCurl != NULL)

                                {

                                                curl_easy_cleanup(hCurl);

                                }

                }

                catch(NCRException &ex)

                {

                                LOG_NCR_EXCEPTION(TRACE_TYPE_ERROR, ex);

                }

}

Can you please helps us what could be the possible reason for this?

Thanks & Regards,
Jitendra Patil.

-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2015-01-23