i'm trying connect ftp server(using domain name), login, , upload file server(it's server). here's code i'm using(based off of examples on libcurl website).
#include <iostream> #include <curl/curl.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <errno.h> #ifdef win32 #include <io.h> #else #include <unistd.h> #endif #define local_file "//home//uploadthis" #define upload_file_as "uploading-as" #define rename_file_to "uploadedfile" upload_file_as #define remote_url "myftpserver" static size_t read_callback(void *ptr, size_t size, size_t nmemb, file *stream) { curl_off_t nread; size_t retcode = fread(ptr, size, nmemb, stream); nread = (curl_off_t)retcode; return retcode; } int main(int argv, char *argc[]) { curl *curl; curlcode res; file *hd_src; struct stat file_info; curl_off_t fsize; struct curl_slist *headerlist=null; static const char buf1[] = "rnfr " upload_file_as; static const char buf2[] = "rnto " rename_file_to; fsize = (curl_off_t)file_info.st_size; hd_src = fopen(local_file, "rb"); curl_global_init(curl_global_all); curl = curl_easy_init(); if (curl) { headerlist = curl_slist_append(headerlist, buf1); headerlist = curl_slist_append(headerlist, buf2); const char *userpass = "username:password"; curl_easy_setopt(curl, curlopt_readfunction, read_callback); curl_easy_setopt(curl, curlopt_url, remote_url); curl_easy_setopt(curl, curlopt_postquote, headerlist); curl_easy_setopt(curl, curlopt_readdata, hd_src); curl_easy_setopt(curl, curlopt_port, 21); curl_easy_setopt(curl, curlopt_upload, 1l); curl_easy_setopt(curl, curlopt_userpwd, userpass); res = curl_easy_perform(curl); curl_slist_free_all(headerlist); curl_easy_cleanup(curl); } fclose(hd_src); curl_global_cleanup(); return 0; }
my problem, run program, connect ftp(i see welcome banner), , 5 "530 please login user , pass." messages, , keep stacking up. puzzled, , i've tried every single possible way of authentication(including creds in url, using deprecated functions previous versions, etc, etc), no avail. got curious, , opened wireshark. request being sent computer put command, , there no login stuff going on @ all. ideas? thank help.
your url not specify protocol. needs start ftp:// ftp server.
without specified protocol, libcurl guesses based on name , pick http - seems have done in case.
also general hint: enable curlopt_verbose see full protocol conversation. helps detect , fix problems faster.