cURL / Mailing Lists / curl-library / Single Mail

curl-library

Renaming files with sftp

From: Joe Ebmeier <ebmeierj_at_iivip.com>
Date: Wed, 18 Jul 2007 16:42:15 -0500

I seem to be having trouble renaming files in the CURLOPT_QUOTE portion of
my curl request. The following test program is a modified version of
http://curl.haxx.se/lxr/source/docs/examples/ftpupload.c.

 

#include <stdio.h>

#include <curl/curl.h>

#include <sys/types.h>

#include <sys/stat.h>

#include <fcntl.h>

#include <unistd.h>

 

#define CURRENT_NAME "bar"

#define NEW_NAME "bar.new"

#define REMOTE_DIR "/interact/LADDER/test/"

#define REMOTE_URL "sftp://javadev2/" REMOTE_DIR

 

int main(int argc, char **argv)

{

  CURL *curl;

  CURLcode res;

 

  struct curl_slist *headerlist=NULL;

  static const char buf_1 [] = "RNFR " REMOTE_DIR "/" CURRENT_NAME;

  static const char buf_2 [] = "RNTO " REMOTE_DIR "/" NEW_NAME;

 

  curl_global_init(CURL_GLOBAL_ALL);

 

  curl = curl_easy_init();

  if(curl)

  {

    /* build a list of commands to pass to libcurl */

    headerlist = curl_slist_append(headerlist, buf_1);

    headerlist = curl_slist_append(headerlist, buf_2);

 

    curl_easy_setopt(curl, CURLOPT_USERPWD, "interact:password");

 

    /* specify target */

    curl_easy_setopt(curl, CURLOPT_URL, REMOTE_URL);

 

    /* pass in that last of FTP commands to run after the transfer */

    curl_easy_setopt(curl, CURLOPT_QUOTE, headerlist);

 

    /* Now run off and do what you've been told! */

    res = curl_easy_perform(curl);

 

    printf("Curl returned: %s\n", curl_easy_strerror(res));

 

    /* clean up the FTP commands list */

    curl_slist_free_all (headerlist);

 

    /* always cleanup */

    curl_easy_cleanup(curl);

  }

 

  curl_global_cleanup();

  return 0;

}

 

 

Using ftp, the file gets renamed as expected. But when I switch to sftp, I
get no errors but the file is not renamed. I am running curl 7.16.4 on a
linux machine. Any ideas what is wrong?

 

Joe Ebmeier

Interact Incorporated

(402) 476-8786 x357

ebmeierj_at_iivip.com

 
Received on 2007-07-19