SOLVED ...
After a larger change, using the rename command as a quote, this requires the full path, including the original name and the full path, including the rename name. I have not tried the path in my other disappointed attempts.
Hi everyone, I have tried all the different combinations, continue to fail and donโt know what I am missing. I am trying to make a simple file rename on an SFTP site using Libcurl. I have been looking for answers to all the questions, but continue to decline.
BTW ... For this test, there is only one file name in the folder, so the problem with the existing file is not overwritten ... And I am the login user who originally uploaded the file for any possible "permissions".
My first test was to get what you would expect as simple syntax, but otherwise. At first I started from the NON-SFTP site ... just plain FTP.
// ex: fpt://mysite.com/subpathNeeded/
curl_easy_setopt(MyCurl, CURLOPT_URL, RemotePath );
// need a "QUOTE" command before rename will occur in postQuote
strcpy_s( NewCmd, _countof(NewCmd), "PWD \0" );
quotelist = curl_slist_append(quotelist, NewCmd );
// NOW, we can issue the rename from and rename to commands
strcpy_s( RenameFrom, _countof(RenameFrom), "RNFR " );
strcat_s( RenameFrom, _countof(RenameFrom), RemoteCurrentFileName );
postquotelist = curl_slist_append( postquotelist, RenameFrom );
strcpy_s( RenameTo, _countof(RenameTo), "RNTO " );
strcat_s( RenameTo, _countof(RenameTo), RemoteRenameToName );
postquotelist = curl_slist_append( postquotelist, RenameTo );
curl_easy_setopt(MyCurl, CURLOPT_QUOTE, quotelist );
curl_easy_setopt(MyCurl, CURLOPT_POSTQUOTE, postquotelist );
// NOW, perform the print working directory, then rename...
MyCurlResult = curl_easy_perform(MyCurl);
It's not a problem. So, now I switch to SFTP, and it fails ... According to the results of the study, SFTP does not like "PWD", but allows "pwd" (case issue), no problem. Then he does not like RNFR and RNTO, but he accepts "mv" (relocation). So, if I'm in SFTP mode, I switch to
// lower case "pwd" print working directory
strcpy_s( NewCmd, _countof(NewCmd), "pwd\0" );
quotelist = curl_slist_append(quotelist, NewCmd );
// "mv" = move "originalfile" "newfile"
strcpy_s( RenameFrom, _countof(RenameFrom), "mv \"\0" );
strcat_s( RenameFrom, _countof(RenameFrom), RemoteCurrentFileName );
strcat_s( RenameFrom, _countof(RenameFrom), "\" \"\0" );
strcat_s( RenameFrom, _countof(RenameFrom), RemoteRenameToName );
strcat_s( RenameFrom, _countof(RenameFrom), "\"\0" );
postquotelist = curl_slist_append( postquotelist, RenameFrom );
Then I get CURL ERROR when I do this ...
, "mv" QUOTE "pwd", , /, . , "RemoteCurrentFileName" "RemoteRenameToName", , . , . :
RemoteCurrentFileName = "FileIWantToRename.txt"
or
RemoteCurrentFileName = "/subpathNeeded/FileIWantToRename.txt"
, , "" "QUOTE" ..
rename "original file" "new file"
. / ... .