k so essentially have this code

HINTERNET hInternet;
    HINTERNET hFtpSession;
    hInternet = InternetOpen(NULL,INTERNET_OPEN_TYPE_DIRECT,NULL,NULL,0);
    hFtpSession = InternetConnect(hInternet, "ftp.freetzi.com", INTERNET_DEFAULT_FTP_PORT, "myuser.freetzi.com", "mypassword", INTERNET_SERVICE_FTP, 0, 0);
    FtpPutFile(hFtpSession, "C:\\log.txt", "mylog.txt", FTP_TRANSFER_TYPE_BINARY, 0);
    if(FtpPutFile(hFtpSession, "C:\\log.txt", "mylog.txt", FTP_TRANSFER_TYPE_BINARY, 0)){
        MessageBox(NULL, "Successfully uploaded log to ftp server!", "Ftp Upload", NULL);
    }else{
        MessageBox(NULL, "Couldn't upload log to ftp server!", "Ftp Upload", NULL);
    }

    InternetCloseHandle(hFtpSession);
    InternetCloseHandle(hInternet);

that allows for an ftp upload of a file. does anybody know how to expand this so that an entire directory can be uploaded?

Recommended Answers

All 4 Replies

You're not giving us any information about how you want this to work but the simple solution would be to iterate over the files in the directory with the following as the body of the loop:

FtpPutFile(hFtpSession, "C:\\log.txt", "mylog.txt", FTP_TRANSFER_TYPE_BINARY, 0);
if(FtpPutFile(hFtpSession, "C:\\log.txt", "mylog.txt", FTP_TRANSFER_TYPE_BINARY, 0)){
        MessageBox(NULL, "Successfully uploaded log to ftp server!", "Ftp Upload", NULL);
}else{
        MessageBox(NULL, "Couldn't upload log to ftp server!", "Ftp Upload", NULL);
}

yes i get what you are saying about iterating files, but it is kind of a restatement of my original question. I need to know how to iterate files and directories from the local machine, and upload them with a matching directory structure on the remote server.

To iterate over the file system, I would recommend Boost (http://www.boost.org/doc/libs/1_38_0/libs/filesystem/doc/index.htm).

It looks like you are using some sort of Windows specific implementation - which I would personally avoid at all costs. Unless you have some reason to do this, I would recommend you consider Qt (www.qtsoftware.com). It will provide you with libraries to iterate over the file system (http://doc.trolltech.com/4.5/qdir.html) and to handle FTP (http://doc.trolltech.com/4.5/network-ftp.html).

Getting even further away from your original question, if you only need to upload a directory of files to an ftp server, this is a great task for Python. Here's an example using the Twisted framework for Python if you are familiar with the language: http://twistedmatrix.com/projects/core/documentation/examples

when im try to compile this .. i get error ..
i include this:

include <wininet.h>
include <iostream>

using namespace std;

why i getting error ?
i learing C++
can anyone help me ?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.