cURL / Mailing Lists / curl-library / Single Mail

curl-library

AW: FTP Error 425

From: André Ogrodowski <ogrodowski_at_melag.de>
Date: Mon, 9 Mar 2015 09:48:10 +0000

Hello Patrick,

thanks for your answer.

Ich have changed the line to:

fp = fopen(filePath, "r");

 But your change request doesn´t solve the Problem. See:

#include <stdio.h>
#include <string.h>

#include <curl/curl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <string.h>
#include <fcntl.h>
#include <errno.h>
#ifdef WIN32
#include <io.h>
#else
#include <unistd.h>
#endif

int main(void)
{
  char filePath[] = "/home/pi/LogFiles/Logfile.txt";
  struct stat fileInfo;
  curl_off_t fsize;
  FILE *fp = NULL;
  CURLcode err;
  struct curl_slist *headerlist=NULL;
  CURL* handle = NULL;
  
  static const char buf_1 [] = "RNFR "; //UPLOAD_FILE_AS;
  static const char buf_2 [] = "RNTO "; //RENAME_FILE_TO;
  
  stat(filePath, &fileInfo);

  fsize = fileInfo.st_size;
  
  fp = fopen(filePath, "r");
  
  curl_global_init(CURL_GLOBAL_ALL);
  handle = curl_easy_init();
  
  headerlist = curl_slist_append(headerlist, buf_1);
  headerlist = curl_slist_append(headerlist, buf_2);
 
  curl_easy_setopt(handle, CURLOPT_POSTQUOTE, headerlist);
  curl_easy_setopt(handle, CURLOPT_VERBOSE, 1L);
  curl_easy_setopt(handle, CURLOPT_UPLOAD, 1L);
  curl_easy_setopt(handle, CURLOPT_FTP_CREATE_MISSING_DIRS, 1L);
  curl_easy_setopt(handle, CURLOPT_PORT, 21L);
  curl_easy_setopt(handle, CURLOPT_URL, "ftp://Nutzer:1234@192.168.70.42/logfile.txt");
  curl_easy_setopt(handle, CURLOPT_INFILESIZE_LARGE, (curl_off_t) fileInfo.st_size);
  curl_easy_setopt(handle, CURLOPT_READDATA, fp);
  
  
  err = curl_easy_perform(handle);
  
  fclose(fp);
  curl_slist_free_all(headerlist);
  curl_easy_cleanup(handle);
  curl_global_cleanup();
  
  return 0;
}

* About to connect() to 192.168.70.42 port 21 (#0)
* Trying 192.168.70.42...
* connected
* Connected to 192.168.70.42 (192.168.70.42) port 21 (#0)
* FTP 0x47a3b8 state change from STOP to WAIT220
< 220 Service ready for new user. (2.1.0.2)
> USER Nutzer
* FTP 0x47a3b8 state change from WAIT220 to USER
< 331 User name okay, need password.
> PASS 1234
* FTP 0x47a3b8 state change from USER to PASS
< 230 User logged in, proceed.
> PWD
* FTP 0x47a3b8 state change from PASS to PWD
< 257 "/" aktuelles Verzeichnis ist das Basis-Verzeichnis (C:\Users\ogrodowski\Desktop\FTP)
* Entry path is '/'
* FTP 0x47a3b8 state change from PWD to STOP
* protocol connect phase DONE
* DO phase starts
> EPSV
* FTP 0x47a3b8 state change from STOP to PASV
* Connect data stream passively
< 502 Command not implemented.
* disabling EPSV usage
> PASV
< 227 Entering Passive Mode (192,168,70,42,233,167)
* Trying 192.168.70.42...
* connected
* Connecting to 192.168.70.42 (192.168.70.42) port 59815
* FTP 0x47a3b8 state change from PASV to STOP
* DO phase is complete
> TYPE I
* FTP 0x47a3b8 state change from STOP to STOR_TYPE
< 200 Type set to TypeI
> STOR logfile.txt
* FTP 0x47a3b8 state change from STOR_TYPE to STOR
< 425 Can't open data connection.
* Failed FTP upload: 425
* DO-MORE phase ends with 25
* Remembering we are in dir ""
* Uploaded unaligned file size (0 out of 384 bytes)
* Connection #0 to host 192.168.70.42 left intact
* Upload failed (at start/before it took off)
> QUIT
* FTP 0x47a3b8 state change from STOR to QUIT
< 221 Service closing control connection.
* FTP 0x47a3b8 state change from QUIT to STOP
* Closing connection #0

------------------
(program exited with code: 0)
Press return to continue

-----Ursprüngliche Nachricht-----
Von: curl-library [mailto:curl-library-bounces_at_cool.haxx.se] Im Auftrag von Patrick Monnerat
Gesendet: Montag, 9. März 2015 10:14
An: libcurl development
Betreff: RE: FTP Error 425

 
André Ogrodowski wrote:

> FILE *fp = NULL;

> fopen(filePath, "r");

> curl_easy_setopt(handle, CURLOPT_READDATA, fp);

You do not assign the open file descrptor. Change as:

        fp = fopen(filePath, "r");

And to prevent leaked descriptors, fclose(fp) after curl_easy_perform().

-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html

-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2015-03-09