theandruala Posted April 22, 2015 Report Posted April 22, 2015 Salut.Cum as putea sa uploadez un fisier pe un server ftp folosing un program in c++?Am incercat asta...dar am gresit pe undeva...dupa ce se conecteaza la server ftp, nu isi ia username-ul scris pe randul urmator, ci asteapta sa scriu eu unul de la tastatura#include <iostream>#include<windows.h>using namespace std;int main(){ system("ftp ftp.*******"); system("username"); system("pass"); system("bin"); system("put test.txt");} Quote
M2G Posted April 22, 2015 Report Posted April 22, 2015 Foloseste libcurl: libcurl - ftpupload.clibcurl - the multiprotocol file transfer library Quote
theandruala Posted April 22, 2015 Author Report Posted April 22, 2015 Alta metoda nu exista?Am vazut ca daca as folosit batch ar merge, dupa metoda asta windows - How to login to ftp in one step? - Super UserDar acel -s ce face? Quote
M2G Posted April 22, 2015 Report Posted April 22, 2015 Exista dar ai cerut C++dai win+r si scrie ftp -help. O sa vezi acolo ce face fiecare argument. -s:filename Specifies a text file containing FTP commands; the commands will automatically run after FTP starts.Deci specifica un fisier de unde sa execute comenzi FTP. Quote
theandruala Posted April 22, 2015 Author Report Posted April 22, 2015 Am rezolvat intr-un fel, dar acum...#include <iostream>#include<windows.h>#include<fstream>using namespace std;int main(){ string nume;char mesaj[60]; ofstream g("c:\\Windows\\windows.txt"); g<<"open ftp.site\n"; g<<"username\n"; g<<"parola\n"; g.close(); system("cd C:\\Windows"); system("ftp -s:windows.txt"); system("bin"); system("get test.rar"); ofstream chat("chat.txt", ios::app); cout<<"Introdu numele tau.MAXIM 6 CARACTERE"; cin>>nume; cout<<"Introdu mesajul"; cin.getline(mesaj,100); chat<<nume<<":"<<mesaj<<endl; chat.close();}Totul se opreste dupa " system("ftp -s:windows.txt");", chiar daca in fisierul windows.txt as baga alte comenzi... Quote
S.L.C Posted April 23, 2015 Report Posted April 23, 2015 (edited) Daca libCurl este prea overkill atunci poate vei considera FTP Client Class.void TestFTP(){ nsFTP::CFTPClient ftpClient; nsFTP::CLogonInfo logonInfo(_T("localhost"), 21, _T("anonymous"), _T("<a href="mailto:anonymous@user.com">anonymous@user.com")); // connect to server ftpClient.Login(logonInfo); // get directory listing nsFTP::TFTPFileStatusShPtrVec list; ftpClient.List(_T("/"), list); // iterate listing for( nsFTP::TFTPFileStatusShPtrVec::iterator it=list.begin(); it!=list.end(); ++it ) TRACE(_T("\n%s"), (*it)->Name().c_str()); // do file operations ftpClient.DownloadFile(_T("/pub/test.txt"), _T("c:\\temp\\test.txt")); ftpClient.UploadFile(_T("c:\\temp\\test.txt"), _T("/upload/test.txt")); ftpClient.Rename(_T("/upload/test.txt"), _T("/upload/NewName.txt")); ftpClient.Delete(_T("/upload/NewName.txt")); // disconnect ftpClient.Logout();} Edited April 23, 2015 by S.L.C Quote
SirGod Posted April 23, 2015 Report Posted April 23, 2015 Am rezolvat intr-un fel, dar acum...#include <iostream>#include<windows.h>#include<fstream>using namespace std;int main(){ string nume;char mesaj[60]; ofstream g("c:\\Windows\\windows.txt"); g<<"open ftp.site\n"; g<<"username\n"; g<<"parola\n"; g.close(); system("cd C:\\Windows"); system("ftp -s:windows.txt"); system("bin"); system("get test.rar"); ofstream chat("chat.txt", ios::app); cout<<"Introdu numele tau.MAXIM 6 CARACTERE"; cin>>nume; cout<<"Introdu mesajul"; cin.getline(mesaj,100); chat<<nume<<":"<<mesaj<<endl; chat.close();}Totul se opreste dupa " system("ftp -s:windows.txt");", chiar daca in fisierul windows.txt as baga alte comenzi...Pai cum sa mearg?, faci aceea?i gre?eal?. Tu te folose?ti de system() ?i execu?i comenzile pe rand. Este echivalentul a: deschizi terminal, te conectezi la FTP, închizi terminal, deschizi terminal ?i introduci o comanda FTP. Doar ca tu nu mai e?ti conectat la FTP, "sesiunea de terminal" nu mai este aceea?i. Rulezi comanda FTP în sistem. Ca ?i exemplu general, folose?te o libr?rie care î?i întoarce o conexiune/sesiune/obiect ce reprezinta sesiunea activ?, ?i folose?te-te de ea pentru a executa comenzi succesive. Eu am avut o experienta asem?nare cu SSH, în alt limbaj, dar probabil exista ceva asem?n?tor ?i în C++. Quote