curl-library
Re: Re-using SFTP connection and CURLOPT_FTP_CREATE_MISSING_DIRS issue
Date: Thu, 13 Mar 2008 09:12:10 -0400
Here is some quick code that reproduces the issue. Make sure that TestDir1
and TestDir2 are not created on the server before running this.
#include <stdio.h>
#include <tchar.h>
#include <curl/curl.h>
#include <iostream>
#include <string>
int _tmain(int argc, _TCHAR* argv[])
{
CURL *curl;
CURLcode curlRes;
std::string remoteFile1 =
"sftp://myserver.com/home/USER/TestDir1/file.zip";
std::string remoteFile2 =
"sftp://myserver.com/home/USER/TestDir2/file.zip";
long serverPort = 22;
std::string loginInfo = "USER:PASS";
std::string localFile = "c:/LOCALFILE.zip";
curlRes = curl_global_init(CURL_GLOBAL_ALL);
curl = curl_easy_init();
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
curl_easy_setopt(curl, CURLOPT_URL, remoteFile1.c_str());
curl_easy_setopt(curl, CURLOPT_PORT, serverPort);
curl_easy_setopt(curl, CURLOPT_USERPWD, loginInfo.c_str());
curl_easy_setopt( curl , CURLOPT_FTP_CREATE_MISSING_DIRS , 1 ) ;
// upload a file to the server
FILE *fp;
fopen_s(&fp, localFile.c_str(), "rb");
if(fp != NULL)
{
curl_easy_setopt(curl, CURLOPT_READDATA, fp);
curl_easy_setopt(curl , CURLOPT_UPLOAD , 1 );
curlRes = curl_easy_perform(curl);
std::cout << "curlRes = " << curlRes << "\n\n" << std::endl;
}
if(fp)
{
fclose(fp);
}
// reset the CURL handle to reuse the connection
curl_easy_reset(curl);
// upload a file to the server
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
curl_easy_setopt(curl, CURLOPT_URL, remoteFile2.c_str());
curl_easy_setopt(curl, CURLOPT_PORT, serverPort);
curl_easy_setopt(curl, CURLOPT_USERPWD, loginInfo.c_str());
curl_easy_setopt( curl , CURLOPT_FTP_CREATE_MISSING_DIRS , 1 ) ;
fopen_s(&fp, localFile.c_str(), "rb");
if(fp != NULL)
{
curl_easy_setopt(curl, CURLOPT_READDATA, fp);
curl_easy_setopt(curl , CURLOPT_UPLOAD , 1 );
curlRes = curl_easy_perform(curl);
std::cout << "curlRes = " << curlRes << "\n\n" << std::endl;
}
if(fp)
{
fclose(fp);
}
return 0;
}
On Thu, Mar 13, 2008 at 12:03 AM, Brian Ulm <ulmbj1_at_gmail.com> wrote:
> The issue appears whether or not curl_easy_reset() is called or not - it
> happens as long as the CURL handle is being reused.
>
> The version of CURL i'm using does have the two patches you provided
> applied.
>
> If you need any more information let me know.
>
> Brian
>
>
>
> From: Daniel Stenberg <daniel_at_haxx.se<daniel_at_haxx.se?Subject=Re:%20Re-using%20SFTP%20connection%20and%20CURLOPT_FTP_CREATE_MISSING_DIRS%20issue>>
>
> Date: Wed, 12 Mar 2008 22:56:57 +0100 (CET)
>
> On Wed, 12 Mar 2008, Brian Ulm wrote:
>
> *> The command sequence is: *
> *> 1.) Initialize CURL handle. *
> *> 2.) Setup CURL options (including CURLOPT_FTP_CREATE_MISSING_DIRS) *
> *> 3.) Upload File #1 *
> *> 4.) Call curl_easy_reset(); *
> *> 5.) Setup the same CURL options (including
> CURLOPT_FTP_CREATE_MISSING_DIRS) *
> *> 6.) Upload File #2 *
>
> Why do the curl_easy_reset()? But more importantly, does it work if you
> don't
> do it?
> Does this libcurl version have the previous two SFTP patches I provided
> applied?
>
Received on 2008-03-13