LibCurl SFTP重命名文件 [英] LibCurl SFTP Rename file

查看:427
本文介绍了LibCurl SFTP重命名文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

已解决...

在四处移动之后,通过使用带引号的命令"rename",它需要包含原始名称的完整路径和包含重命名目标的完整路径.在其他失败的尝试中,我没有尝试过该路径.

After more shifting around, by using the "rename" as quoted command, it required the full path inclusive of the original name and full path inclusive of rename-to destination. I didn't try with the path in my other frustrated attempts.

大家好,我尝试了所有不同的组合,但不断失败,不知道自己缺少什么.我正在尝试使用Libcurl在SFTP站点上进行简单的文件重命名.我到处都在寻找答案,但是请保持简短.

Hi all, I've tried all different combinations, keep failing and don't know what I'm missing. I'm trying to do a simple file rename on a SFTP site using Libcurl. I've looked all over for answers, but keep coming up short.

BTW ...对于此测试,该文件夹中只有一个文件名,因此没有有关现有文件覆盖的问题...而且我是最初上传文件以解决任何可能的权限"问题的登录用户

BTW... For this testing, there is only one file name in the folder, so no issue about existing file overwrites... And I'm the login user who originally uploaded the file for any possible "permissions" issues.

我的第一个测试是获得正确语法所期望的结果,但否则得到结果.我首先从NON-SFTP网站开始...只是常规FTP.

My first test was to get the what would be expected as simple syntax correct, but resulted otherwise. I started with a NON-SFTP site first... just regular 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); 

这没问题.因此,现在,我切换到SFTP,但失败了...通过研究,SFTP不喜欢"PWD",但允许"pwd"(案例问题),这没有问题.然后,它不喜欢RNFR和RNTO,但是接受"mv"(移动).因此,如果我处于SFTP模式,则更改为

This works no problem. So now, I switch over to SFTP and it fails... By researching, SFTP doesn't like "PWD", but does allow "pwd" (case issue), no problem. Then, it doesn't like the RNFR and RNTO but does accept "mv" (move). So, if I'm in SFTP mode, I change 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 );

执行此操作后,我得到一个CURL错误...

I then get a CURL ERROR when I perform this...

但是,如果我不尝试使用"mv"命令,而仅发送"pwd"的QUOTE命令,则可以正常运行,并且确实正确列出了我要在其中重命名文件的预期文件夹/子目录所以我知道它在正确的目录中.我在"RemoteCurrentFileName"和"RemoteRenameToName"中具有的值只是文件的茎,分别没有它们的完整路径.我也尝试过包括完整路径,并且两个版本都失败了.例如:

However, if I don't try the "mv" command and only send the QUOTE command of "pwd", it goes through fine and it does properly list the expected folder/subdirectory I'm trying to rename the file in. So I know its in the proper directory. The values I have in the "RemoteCurrentFileName" and "RemoteRenameToName" are just the stems of the file, no full path to them respectively. I've also tried including the full path as well and both versions fail. Ex:

RemoteCurrentFileName = "FileIWantToRename.txt"
    or 
RemoteCurrentFileName = "/subpathNeeded/FileIWantToRename.txt"

此外,我查看了文档,并指出重命名"是有效的"QUOTE"命令,并且也尝试过该操作.

Additionally, I've looked at the documentation and noted "rename" is a valid "QUOTE" command and tried that too..

rename "original file" "new file"

那也失败了

这应该不难做到.我想念的是什么简单/愚蠢……这真令人沮丧.

This should not be this difficult to do. What simple/stupid am I missing... This is totally frustrating.

推荐答案

已解决...

在四处移动之后,通过使用带引号的命令"rename",它需要包含原始名称的完整路径和包含重命名目标的完整路径.在其他失败的尝试中,我没有尝试过路径

After more shifting around, by using the "rename" as quoted command, it required the full path inclusive of the original name and full path inclusive of rename-to destination. I didn't try with the path in my other frustrated attempts

strcpy_s( RenameFrom, _countof(RenameFrom), "rename \"\0" );
strcat_s( RenameFrom, _countof(RenameFrom), RemoteCurrentFileNameWithFullPath );
strcat_s( RenameFrom, _countof(RenameFrom), "\" \"\0" );
strcat_s( RenameFrom, _countof(RenameFrom), RemoteRenameToNameWithFullPath );
strcat_s( RenameFrom, _countof(RenameFrom), "\"\0" );
quotelist = curl_slist_append( quotelist, RenameFrom );

MyCurlResult = curl_easy_perform(MyCurl); 

这篇关于LibCurl SFTP重命名文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆