Etichetă: c++ ftp windows api

Send a File through Ftp c++ Windows Api Snippet

This article has been written before more than 24months, information might old.

Simplu sinppet pentru a trimite o singura fila prin ftp folosind API-ul windows-ului se mai poate folosind alte cateva librari existente cum ar fi libftp sau curl .

bool netAzFtpSendFile(LPCWSTR host,LPCWSTR user,LPCWSTR pass,LPCWSTR fPath,LPCWSTR fRemName,bool binaryTransfer=true){
HINTERNET hINet, hConn; BOOL PF;
hINet =
InternetOpen(L"netAzFtpSendFile/1.0",
INTERNET_OPEN_TYPE_PRECONFIG,
NULL,NULL,0);
if ( !hINet )return false;
else hConn = InternetConnect(hINet,host,21,user,pass,
INTERNET_SERVICE_FTP,0,0);
if ( !hConn ) { InternetCloseHandle(hINet); return false; }
else{ if(binaryTransfer) 
PF = FtpPutFile(hConn,fPath,fRemName,
FTP_TRANSFER_TYPE_BINARY,0);
else PF = FtpPutFile(hConn,fPath,fRemName,
FTP_TRANSFER_TYPE_ASCII,0);}
InternetCloseHandle(hINet); 
if(PF) return true;else return false;
}