使用libcurl制作新目录
Making New Directory with libcurl
我一直在修改libcurl,到目前为止它还不错。我有一些事情让我再次感到困惑。我需要创建一个到远程服务器的目录,这里有的问题
-
我在CURLOPT_URL中传递什么?它是根URL还是完整的第i个目录?
-
我希望在创建目录时产生连锁反应,也就是说,如果我有diectory/abc/def/ghi,那么如果它们不存在,就应该创建它们。我尝试过CURLOPT_FTP_CREATE_MISSING_DIRS,但不起作用。
-
尝试MKD失败了,我不能确定为什么。以下是应用的相关代码和日志
代码
CURL* handle = curl_easy_init();
SetHandleOptions(handle); //set options
CURLcode res;
wxString uploadUrl =....;//full URL with path like ftp.xyz.com/public_html/dir1/
wxString command1 = "MKD "+uploadUrl;
wxString command2 = "CWD "+uploadUrl;
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, command1.c_str());
headers = curl_slist_append(headers, command2.c_str());
curl_easy_setopt(handle, CURLOPT_QUOTE, headers);
const char* uploadUrlStr = uploadUrl.c_str();
if(handle)
{
//do file upload here
/* upload to this place */
curl_easy_setopt(handle, CURLOPT_URL, uploadUrlStr);
/* enable verbose for easier tracing */
curl_easy_setopt(handle, CURLOPT_VERBOSE, 1L);
curl_easy_setopt(handle, CURLOPT_FTP_CREATE_MISSING_DIRS, 1L);
curl_easy_setopt(handle, CURLOPT_QUOTE, headers);
res = curl_easy_perform(handle);
if(res==CURLE_OK)
{
SendMessage(_("Successfully Created Directory: ")+uploadUrl, HERROR_TYPE_WARNING);
}
else
{
//send error message
wxString str(curl_easy_strerror(res));
SendMessage(str);
}
/* always cleanup */
curl_easy_cleanup(handle);
}
else
{
SendMessage(_("Could Not Connect to Server: Invalid Handle"), HERROR_TYPE_CRITICAL);
}
curl_slist_free_all(headers);
日志
----------Wed Dec 18 01:33:15 2013----------
Changing Directory to / [01:33:20]
Successfully logged In [01:33:21]
No error [01:33:24]
Starting Files List Fetching... [01:33:24]
No error [01:33:26]
[01:33:32]
IDN support not present, can't parse Unicode domains
[01:33:32]
About to connect() to ftp.hosanna.site40.net port 21 (#2)
[01:33:33]
Trying 31.170.162.203...
[01:33:33]
Adding handle: conn: 0x7fffd0013110
[01:33:33]
Adding handle: send: 0
[01:33:33]
Adding handle: recv: 0
[01:33:33]
Curl_addHandleToPipeline: length: 1
[01:33:33]
- Conn 2 (0x7fffd0013110) send_pipe: 1, recv_pipe: 0
[01:33:33]
[01:33:33]
[01:33:33]
Closing connection 3
[01:33:33]
Couldn't resolve host name [01:33:33]
Connected to ftp.hosanna.site40.net (31.170.162.203) port 21 (#2)
[01:33:34]
220---------- Welcome to Pure-FTPd [privsep] ----------
220-You are user number 9 of 500 allowed.
220-Local time is now 17:33. Server port: 21.
220-This is a private system - No anonymous login
220 You will be disconnected after 3 minutes of inactivity.
[01:33:35]
220-You are user number 9 of 500 allowed.
220-Local time is now 17:33. Server port: 21.
220-This is a private system - No anonymous login
220 You will be disconnected after 3 minutes of inactivity.
[01:33:35]
220-Local time is now 17:33. Server port: 21.
220-This is a private system - No anonymous login
220 You will be disconnected after 3 minutes of inactivity.
[01:33:35]
220-This is a private system - No anonymous login
220 You will be disconnected after 3 minutes of inactivity.
[01:33:35]
220 You will be disconnected after 3 minutes of inactivity.
[01:33:35]
USER xxxxxx
[01:33:35]
331 User xxxxxx OK. Password required
tes of inactivity.
-You are user number 9 of 500 allowed.
220-Local time is now 17:33. Server port: 21.
220-This is a private system - No anonymous login
220 You will be disconnected after 3 minutes of inactivity.
[01:33:35]
PASS xxxxxx
[01:33:35]
230-OK. Current restricted directory is /
230-124 files used (1%) - authorized: 10000 files
230 3051 Kbytes used (0%) - authorized: 1536000 Kb
220-This is a private system - No anonymous login
220 You will be disconnected after 3 minutes of inactivity.
[01:33:36]
230-124 files used (1%) - authorized: 10000 files
230 3051 Kbytes used (0%) - authorized: 1536000 Kb
220-This is a private system - No anonymous login
220 You will be disconnected after 3 minutes of inactivity.
[01:33:36]
230 3051 Kbytes used (0%) - authorized: 1536000 Kb
220-This is a private system - No anonymous login
220 You will be disconnected after 3 minutes of inactivity.
[01:33:36]
PWD
[01:33:36]
257 "/" is your current location
ized: 1536000 Kb
files used (1%) - authorized: 10000 files
230 3051 Kbytes used (0%) - authorized: 1536000 Kb
[01:33:37]
Entry path is '/'
[01:33:37]
MKD ftp://ftp.hosanna.site40.net/public_html/Zulu names and meanings
[01:33:37]
ftp_perform ends with SECONDARY: 0
[01:33:37]
550-Can't create directory: No such file or directory
550-124 files used (1%) - authorized: 10000 files
550 3051 Kbytes used (0%) - authorized: 1536000 Kb
a private system - No anonymous login
220 You will be disconnected after 3 minutes of inactivity.
[01:33:37]
550-124 files used (1%) - authorized: 10000 files
550 3051 Kbytes used (0%) - authorized: 1536000 Kb
a private system - No anonymous login
220 You will be disconnected after 3 minutes of inactivity.
[01:33:37]
550 3051 Kbytes used (0%) - authorized: 1536000 Kb
a private system - No anonymous login
220 You will be disconnected after 3 minutes of inactivity.
[01:33:37]
QUOT command failed with 550
[01:33:37]
Closing connection 2
[01:33:37]
Quote command returned error [01:33:37]
确保路径的形式为/public_html/somedir而不是ftp://ftp.somesite.com/public_html/somedir
这就是我的代码出了问题。所以我通过删除URL来解决这个问题。我认为应该有一个关于libcurl的章节来解释预期的URL格式。一旦我完全掌握了它,我就会做出贡献!
相关文章:
- 使用新行和不使用新行读取文件
- 如何运行位于boost/libs/python/example/tutorial目录中的hello.cpp和Jamfil
- 为什么构建目录中新构建的共享库与安装目录中的副本具有不同的依赖项集?
- 如何将图像传入C++可执行文件并将输出图像存储在新目录中?
- 使用 Poco::zip 添加新目录始终给出异常
- 将文件复制到 pro/pri 文件中的新目录
- 使用libcurl和C 将图片上传到密码保护的目录
- C++读取添加到目录中的新文件
- inotify:如何在传输完成后通知目录中的新文件
- C++:如何使用libcurl检查FTP服务器上是否存在目录
- 使用libcurl制作新目录
- 如何在 Linux 中的单独/包含目录中编译额外/更新的库以及新程序
- inotify-在目录树中的几个级别之后,无法将手表添加到新创建的目录中
- Win32 API从一个目录复制图片文件到新的/现有的目录
- 在SDL中创建一个新文件夹或目录
- VS Express 2013 -默认为每个新项目添加.h文件,使其位于相同的目录下
- 在c++中读取写在文件中的目录位置,并在该目录中创建新文件
- 如何检查目录中的新文件
- 不会创建新目录
- Visual Studio将新文件放入错误的目录中