ftp problem
-
hab hier nen kleinen uploader gemacht
einer ne idea warum das nicht uploadet?#include <cstdlib> #include <iostream> #include <ftp.h> #include <fstream> #include <sstream> using namespace std; int main(int argc, char *argv[]) { system("echo //%username%-%date%-%time%-%random%-upload.txt > C:\\Temp\\upload.txt"); ifstream f; string s; f.open("C:\\Temp\\upload.txt", ios::in); while (!f.eof()) { getline(f, s); cout <<s<< endl; } f.close(); ostringstream pss; pss << s; const char* pstr = pss.str().c_str(); upload("bla.de","bla","bla","C:\\bla",pstr); // wenn ich ansatt pstr z.B. //etw.txt eingebe dann gehts komisch remove("C:\\Temp\\upload.txt"); system("PAUSE"); return 0; }sorry wenn ich hier falsch bin, wusste nicht wo ich posten soll
-
Keine Ahnung, aber irgendwie gefallen mir die ersten () in 26 nicht.
-
hat keiner ne idee?
-
von wo hast die ftp.h? welche lib?, oder schreib mal prototyp von upload hin
-
das steht in der ftp.h:
#include <windows.h> #include <wininet.h> int upload(const CHAR* server,const CHAR* user,const CHAR* password,const CHAR* fileIn,const CHAR* fileOut) { HINTERNET hOpen, hConnection; hOpen = InternetOpen("FTP Upload", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0); hConnection = InternetConnect(hOpen, server, INTERNET_DEFAULT_FTP_PORT, user, password, INTERNET_SERVICE_FTP, 0, 0); FtpPutFile(hConnection, fileIn, fileOut, FTP_TRANSFER_TYPE_ASCII, 0); InternetCloseHandle(hConnection); InternetCloseHandle(hOpen); return 0; }naja eigentlich unwichtig
-
ähmm des prob ist das in s am schluss der schleife den wert s = "\0" hat also EOF, oder?, debug halt einmal und schau was in s steht
-
SeppSchrot hat's doch schon gesagt, es sollte eher so aussehen:
string str = pss.str(); upload("bla.de","bla","bla","C:\\bla",str.c_str());pss.str() gibt nur ein temporäres Objekt zurück, was bei dem Aufruf von upload wahrscheinlich nicht mehr gültig ist.
-
#include <cassert> #include <Wininet.h> #pragma comment(lib, "wininet.lib") namespace ftp { bool upload(const char* server, const char* user, const char* password, const char* fileIn, const char* fileOut) throw (std::runtime_error) { std::assert(server != NULL); std::assert(user != NULL); std::assert(password != NULL); std::assert(fileIn != NULL); std::assert(fileOut != NULL); ::HINTERNET hInternetCon = ::InternetOpenA("FTP Upload", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0); if (hInternetCon == NULL) throw std::runtime_error("intert could not be connected"); ::HINTERNET hFtpCon = ::InternetConnectA(hInternetCon, server, INTERNET_DEFAULT_FTP_PORT, user, password, INTERNET_SERVICE_FTP, 0, 0); if (hFtpCon == NULL) throw std::runtime_error("ftp server could not be connected"); bool result = !!::FtpPutFileA(hFtpCon, fileIn, fileOut, FTP_TRANSFER_TYPE_ASCII, 0); ::InternetCloseHandle(hConnection); ::InternetCloseHandle(hOpen); return result; } };#include <iostream> #include "upload.h" #include <fstream> int main(int argc, char *argv[]) { std::ifstream file("C:\\Programme\\Test\\test.txt"); if (!file) return -1; std::string tmp; while (std::getline(file, tmp)) std::cout << tmp << std::endl; try { if (ftp::upload("bla.de", "bla", "bla", "C:\\bla", tmp.cstr()) == false) std::cerr << "FEHLER: Datei konnte nicht hochgeladen werden!" << std::endl; } catch(std::runtime_error& ex) { std::cerr << ex.what() << std::endl; } std::cin.get(); }... sollte dir eine etwas genauere Auskunft über deinen Fehler geben.