Title: rename file on sftp with curl on php
Tags: php;curl
Question: Its possible to rename a file on sftp server using curl on php?
I use this function to connect but I don't know if its possible to rename a file on the server
function get_test_lines($file_name){
$c = curl_init(&quot;sftp://&quot;.SFTP_USER.&quot;:&quot;.SFTP_PASSWORD.&quot;@&quot;.SFTP_HOST.&quot;/data/&quot;.$file_name.&quot;.txt&quot;);
curl_setopt($c, CURLOPT_PROTOCOLS, CURLPROTO_SFTP);
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec($c);
curl_close($c);
return $data;


Here is another answer: Maybe this is relevant: rename using curl on FTP (http://www.mukeshkumar.net/articles/curl/how-to-use-curl-command-line-tool-with-ftp-and-sftp);
curl -p - --insecure  &quot;ftp://151.154.11.224:21/CurlPutTest/&quot; --user &quot;testuser:testpassword&quot; -Q &quot;-RNFR /CurlPutTest/testfile.xml&quot;  -Q &quot;-RNTO /CurlPutTest/testfile.xml.tmp&quot;   --ftp-create-dirs
Perhaps there are similar options for SFTP, although SFTP and FTP are quite different

Here is another answer: Yes, using rename command. Quotation marks &quot; are required if filename contains spaces. Use always full path from the sftp root.
curl_setopt($c, CURLOPT_POSTQUOTE, array('rename &quot;/' . $file_name_from . '&quot; &quot;/' . $file_name_to .'&quot;'));

{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 2, 'CommentCount': 0, 'ContentLicense': 'CC BY-SA 4.0', 'CreationDate': '2021:00:02/17/21', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<php><curl>', 'Title': 'rename file on sftp with curl on php', 'ViewCount': 399, 'id': 66244228, 'user_AboutMe': None, 'user_AccountId': 20738128.0, 'user_DisplayName': 'a_crl3', 'user_Reputation': 41.0, 'user_Views': 15.0, 'user_id': 15228510.0}}