Jump to content
theandruala

c++ conectare server ftp

Recommended Posts

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");
}

Link to post
Share on other sites

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.

Link to post
Share on other sites

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...

Link to post
Share on other sites

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 by S.L.C
Link to post
Share on other sites
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++.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...