cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: Renaming files with sftp

From: James Housley <jim_at_thehousleys.net>
Date: Wed, 18 Jul 2007 18:09:04 -0400

On Jul 18, 2007, at 5:42 PM, Joe Ebmeier wrote:

> 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?

sftp is not ftp.

You want to use a single request of "rename namefrom nameto"

Jim

--
/"\   ASCII Ribbon Campaign  .
\ / - NO HTML/RTF in e-mail  .
  X  - NO Word docs in e-mail .
/ \ -----------------------------------------------------------------
                      http://www.FreeBSD.org     The Power to Serve
jim@TheHousleys.Net  http://www.TheHousleys.net
---------------------------------------------------------------------
"Eagles may soar, but weasels don't get sucked into jet engines"
     -- Anon
Received on 2007-07-19