Форум программистов
 

Восстановите пароль или Зарегистрируйтесь на форуме, о проблемах и с заказом рекламы пишите сюда - alarforum@yandex.ru, проверяйте папку спам!

Вернуться   Форум программистов > C/C++ программирование > Общие вопросы C/C++
Регистрация

Восстановить пароль
Повторная активизация e-mail

Купить рекламу на форуме - 42 тыс руб за месяц

Ответ
 
Опции темы Поиск в этой теме
Старый 14.01.2011, 20:38   #1
Hichigo
Пользователь
 
Регистрация: 19.07.2010
Сообщений: 40
По умолчанию curl + ftp аутентификация

Искал тут примеры работы с ftp но не нашел с аутентификацией.
какой функцией надо заполнять опцию, логин и пароль?
Hichigo вне форума Ответить с цитированием
Старый 15.01.2011, 00:48   #2
oleg kutkov
Unix C++ developer
Форумчанин
 
Аватар для oleg kutkov
 
Регистрация: 16.04.2007
Сообщений: 651
По умолчанию

http://curl.haxx.se/libcurl/c/curl_e...CURLOPTUSERPWD
oleg kutkov вне форума Ответить с цитированием
Старый 15.01.2011, 09:55   #3
Hichigo
Пользователь
 
Регистрация: 19.07.2010
Сообщений: 40
По умолчанию

CURLOPT_USERNAME & CURLOPT_PASSWORD ?
Hichigo вне форума Ответить с цитированием
Старый 15.01.2011, 10:07   #4
oleg kutkov
Unix C++ developer
Форумчанин
 
Аватар для oleg kutkov
 
Регистрация: 16.04.2007
Сообщений: 651
По умолчанию

Ну разумеется.
Код:
curl_setopt(curl, CURLOPT_URL,"ftp://ftp.gnu.org");
curl_setopt(curl, CURLOPT_USERPWD, "anonymous:your@email.com");
oleg kutkov вне форума Ответить с цитированием
Старый 11.05.2014, 10:13   #5
Alsou93
 
Регистрация: 06.04.2012
Сообщений: 9
По умолчанию Не получается подключиться по ftp и залить файл

В программе я авторизуюсь и закачиваю файл с локалки на удаленный ftp, программа компилится, но у меня выходит исключение.
Может кто-нибудь уже делал что-то подобное? можете мне сделать кто-нибудь эту программу, откомпилировать и прислать ее, ну а я в долгу не останусь. просто она мне вообще позарез нужна, выручите пожалуйста.
Код:
#include "StdAfx.h"
#include <stdio.h>
#include <string.h>
 
#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
 
/*
 * This example shows an FTP upload, with a rename of the file just after
 * a successful upload.
 *
 * Example based on source code provided by Erick Nuwendam. Thanks!
 */
 
#define LOCAL_FILE      "I:\\korm.txt"
#define UPLOAD_FILE_AS  "korm.txt"
#define REMOTE_URL      "ftp://ftpupload1/dot/"  UPLOAD_FILE_AS
#define USERNAME        "Alsou93"
#define PASSWORD        "mblspxnx"
 
int main(void)
{
  CURL *curl;
  CURLcode res;
  FILE *hd_src;
  struct stat file_info;
  curl_off_t fsize;
 
  struct curl_slist *headerlist=NULL;
  static const char buf_1 [] = "RNFR " UPLOAD_FILE_AS;
 
  /* get the file size of the local file */
  if(stat(LOCAL_FILE, &file_info)) {
    printf("Couldnt open '%s': %s\n", LOCAL_FILE, strerror(errno));
    return 1;
  }
  fsize = (curl_off_t)file_info.st_size;
 
 
  /* get a FILE * of the same file */
  hd_src = fopen(LOCAL_FILE, "rb");
 
  /* In windows, this will init the winsock stuff */
  curl_global_init(CURL_GLOBAL_ALL);
 
  /* get a curl handle */
  curl = curl_easy_init();
  if(curl) {
    /* build a list of commands to pass to libcurl */
    headerlist = curl_slist_append(headerlist, buf_1);
 
    /* set login and password */
    curl_easy_setopt(curl, CURLOPT_USERNAME, USERNAME);
    curl_easy_setopt(curl, CURLOPT_PASSWORD, PASSWORD);
 
    /* enable uploading */
    curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L);
 
    /* specify target */
    curl_easy_setopt(curl,CURLOPT_URL, REMOTE_URL);
 
    /* pass in that last of FTP commands to run after the transfer */
    curl_easy_setopt(curl, CURLOPT_POSTQUOTE, headerlist);
 
    /* now specify which file to upload */
    curl_easy_setopt(curl, CURLOPT_READDATA, hd_src);
 
    /* Set the size of the file to upload (optional).  If you give a *_LARGE
       option you MUST make sure that the type of the passed-in argument is a
       curl_off_t. If you use CURLOPT_INFILESIZE (without _LARGE) you must
       make sure that to pass in a type 'long' argument. */
    curl_easy_setopt(curl, CURLOPT_INFILESIZE_LARGE,
                     (curl_off_t)fsize);
 
    /* Now run off and do what you've been told! */
    res = curl_easy_perform(curl);
    /* Check for errors */
    if(res != CURLE_OK)
      fprintf(stderr, "curl_easy_perform() failed: %s\n",
              curl_easy_strerror(res));
 
    /* clean up the FTP commands list */
    curl_slist_free_all (headerlist);
 
    /* always cleanup */
    curl_easy_cleanup(curl);
  }
  fclose(hd_src); /* close the local file */
 
  curl_global_cleanup();
  return 0;
}
Alsou93 вне форума Ответить с цитированием
Ответ


Купить рекламу на форуме - 42 тыс руб за месяц

Опции темы Поиск в этой теме
Поиск в этой теме:

Расширенный поиск


Похожие темы
Тема Автор Раздел Ответов Последнее сообщение
базовая аутентификация Dimarik PHP 8 16.07.2010 20:56
Аутентификация репозитория Freemaks Операционные системы общие вопросы 5 04.07.2010 20:21
[C++] Аутентификация. Ветер Фриланс 4 25.05.2010 11:03
Аутентификация пользователя didar_ Общие вопросы Delphi 18 10.11.2009 17:11
FTP, аутентификация, событие onCommand spoool Работа с сетью в Delphi 9 15.04.2009 13:37