Ftp upload problem

Hello guys, I'm Samuel from Italy and this is my first message, I'm a noob and I'm a php developer. I need a C++ software that upload one time per day one backup on ftp. Computers are all Windows 7.

I write all the code that make a backup etc, but I cannot edit/write the right code to upload this file on our ftp. (I wanna be honest, I haven't time to study very well c++ and usually I copy/paste and edit code).

I found this code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <CkFtp2.h>
#include <CkString.h>
#include <windows.h>
#include <stdio.h> 

#include <iostream>
using std::cout;
using std::endl;


void ChilkatSample(void)
    {
    CkFtp2 ftp;

    bool success;

    //  Any string unlocks the component for the 1st 30-days.
    success = ftp.UnlockComponent("Anything for 30-day trial");
    if (success != true) {
        printf("%s\n",ftp.lastErrorText());
        return;
    }

    ftp.put_Hostname("ftp.chilkatsoft.com");
    ftp.put_Username("****");
    ftp.put_Password("****");

    //  The default data transfer mode is "Active" as opposed to "Passive".

    //  Connect and login to the FTP server.
    success = ftp.Connect();
    if (success != true) {
        printf("%s\n",ftp.lastErrorText());
        return;
    }

    //  Change to the remote directory where the file will be uploaded.
    success = ftp.ChangeRemoteDir("junk");
    if (success != true) {
        printf("%s\n",ftp.lastErrorText());
        return;
    }

    //  Upload a file.
    CkString localFilename;
    localFilename = "hamlet.xml";
    CkString remoteFilename;
    remoteFilename = "hamlet.xml";

    success = ftp.PutFile(localFilename,remoteFilename);
    if (success != true) {
        printf("%s\n",ftp.lastErrorText());
        return;
    }

    ftp.Disconnect();

    printf("File Uploaded!\n");
    }


But when I try to compile I have this error:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
C:\Users\utente\Desktop>g++ send.cpp -o send.exe
In file included from c:\mingw\include\ckftp2.h:21:0,
                 from send.cpp:1:
c:\mingw\include\CkString.h:107:24: error: 'SYSTEMTIME' has not been declared
  void appendDateRfc822(SYSTEMTIME &sysTime);
                        ^
c:\mingw\include\CkString.h:109:27: error: 'SYSTEMTIME' has not been declared
  void appendDateRfc822Gmt(SYSTEMTIME &sysTime);
                           ^
In file included from send.cpp:1:0:
c:\mingw\include\ckftp2.h:209:33: error: 'FILETIME' has not been declared
  bool GetCreateTime(long index, FILETIME &outFileTime);
                                 ^
c:\mingw\include\ckftp2.h:210:37: error: 'FILETIME' has not been declared
  bool GetLastAccessTime(long index, FILETIME &outFileTime);
                                     ^
c:\mingw\include\ckftp2.h:211:39: error: 'FILETIME' has not been declared
  bool GetLastModifiedTime(long index, FILETIME &outFileTime);
                                       ^
c:\mingw\include\ckftp2.h:213:33: error: 'SYSTEMTIME' has not been declared
  bool GetCreateTime(long index, SYSTEMTIME &outSysTime);
                                 ^
c:\mingw\include\ckftp2.h:213:7: error: 'bool CkFtp2::GetCreateTime(long int, in
t&)' cannot be overloaded
  bool GetCreateTime(long index, SYSTEMTIME &outSysTime);
       ^
..ETC ETC ETC..
       ^


I'm using Windows and MinGW as a compiler.

Someone have some idea to fix this problem? or have you some code that works? (I tried this day I think 10/15 different codes but didn't works..)

Thank you for your time.
closed account (NUj6URfi)
It's an issue in your headers. I would recommend looking at the code of FileZilla. It's proven to work and has large support as far as ftp goes. Also, you could do a windows's equivelent of a cron job if that exists. Something that once a day uses a ftp client via cli.
solved with this code:


1
2
3
4
5
    HINTERNET hSession = InternetOpen(NULL, INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
    HINTERNET hService = InternetConnect(hSession, "MY FTP domain or IP", INTERNET_DEFAULT_FTP_PORT, "user", "pass", INTERNET_SERVICE_FTP, INTERNET_FLAG_PASSIVE, 0);
    FtpPutFile(hService, "file_on_hd.txt", "file_on_ftp.txt" , FTP_TRANSFER_TYPE_BINARY, 0);
    InternetCloseHandle(hService);
    InternetCloseHandle(hSession);


Very important use WININET.LIB or doesn't works!
Topic archived. No new replies allowed.