2013-12-17 2 views
0

libcurl을 사용해 봤는데 지금까지 좋은 점이있었습니다. 나는 약간 혼란스러워하는 몇 가지 일이 있습니다. 원격 서버에 대한 디렉토리를 생성해야하는데 여기에 문제가 있습니다.libcurl을 사용하여 새 디렉토리 만들기

  1. CURLOPT_URL에서 무엇을 전달합니까? 루트 URL 또는 전체 i 번째 디렉토리입니까?

  2. diectory/abc/def/ghi가 있으면 디렉토리가 생성되지 않은 경우 생성해야합니다. CURLOPT_FTP_CREATE_MISSING_DIRS 시도했지만 작동하지 않습니다.

  3. 시도한 MKD 그것은 실패하고 나는 확실히 말할 수 없다. 다음은 관련 코드이며,

CODE

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); 

LOG

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

답변

1

이 경로는 형태로되어 있는지 확인합니다 응용 프로그램에서 로그인/public_html을/somedir하지 ftp://ftp.somesite.com/public_html/somedir

그것이 내 코드에서 잘못되었다. 그래서 URL을 제거하여 해결했습니다. libcurl에 예상 URL 형식을 설명하는 절이 있어야한다고 생각합니다. 나는 그것을 완전히 이해하면 그것을 기여할 것입니다!

관련 문제