FTP

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
#include<iostream>
#include<windows.h>
#include<Wininet.h>

using namespace std;


int main()
{
    HINTERNET hInternet;
    HINTERNET hFtp;


    hInternet=InternetOpen(0,INTERNET_OPEN_TYPE_DIRECT,0,0,0);
    if(hInternet == NULL)
      cout<<"\n1)Something goes wrong...\n";
    else
      cout<<"\n1)Everything is perfect...\n";



    hFtp = InternetConnect(hInternet,"xxx.xxx.xxx",INTERNET_DEFAULT_FTP_PORT,"user","pass",INTERNET_SERVICE_FTP,0,0);
    if(hFtp == NULL)
      cout<<"\n2)Something goes wrong...\n";
     else
      cout<<"\n2)Everything is perfect...\n";


    char szFile[] = "log";
    strcat(szFile,".txt");

    FtpPutFile(hFtp,szFile,"file.txt",INTERNET_FLAG_TRANSFER_BINARY,0);



    InternetCloseHandle(hFtp);
    InternetCloseHandle(hInternet);

    return 0;

}


This is my source.It works perfect,and in my ftp file a file named "file.txt" is created from this code
FtpPutFile(hFtp,szFile,"file.txt",INTERNET_FLAG_TRANSFER_BINARY,0);

But i have two questions:
1)With this code
1
2
char szFile[] = "log";
    strcat(szFile,".txt");


It works,but if i change the char szFile[] = "log"; to char szFile[] = "something else"; It does not work.Why?

2)How i can put something into the file that is created?

Thanks...
http://cplusplus.com/forum/windows/89825/

We already were helping you in this thread?

1) What is "something else"? Why not just create it with the .txt already applied? It looks like a completely unnecessary function call. Anyways, I'm surprised the former works. That should cause a segmentation fault. Try creating an array that is actually big enough to hold what you're looking for, or use std::string.

2) Using file I/O. http://www.cplusplus.com/reference/cstdio/
Topic archived. No new replies allowed.