środa, 24 stycznia 2018

Checking files and sending info to the server (Visual C++)



private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
System::Int32 i;
System::Int32 value;
listBox1->Items->Clear();
listBox2->Items->Clear();
array<Byte>^ c_Buf=gcnew array<Byte>(1024);
array<Byte>^ wind_Buf=gcnew array<Byte>(1024);
StreamWriter^ file_C=gcnew StreamWriter("InfoC.txt",0,System::Text::Encoding::Default);
StreamWriter^ file_Wind=gcnew StreamWriter("InfoWind.txt",0,System::Text::Encoding::Default);
DirectoryInfo^ my_C=gcnew DirectoryInfo("c:");
DirectoryInfo^ my_Wind=gcnew DirectoryInfo("c:\\Windows");
array<FileInfo^>^files_C=my_C->GetFiles("*.*");
array<FileInfo^>^files_Wind=my_Wind->GetFiles("*.*");
for(i=0;i<files_C->Length;i++)
{
listBox1->Items->Add(files_C[i]->Name+"---"+files_C[i]->Length);
}
for(i=0;i<files_Wind->Length;i++)
{
listBox2->Items->Add(files_Wind[i]->Name+"---"+files_Wind[i]->Length);
}
Uri^ u_Adress1=gcnew Uri("ftp://myName.edu.com/InfoC.txt");
Uri^ u_Adress2=gcnew Uri("ftp://myName.edu.com/InfoWind.txt");
FtpWebRequest^ req_C=dynamic_cast<FtpWebRequest^>(WebRequest::Create(u_Adress1));
FtpWebRequest^ req_Wind=dynamic_cast<FtpWebRequest^>(WebRequest::Create(u_Adress2));
req_C->Credentials=gcnew NetworkCredential("anonymus","my_name@.com");
req_Wind->Credentials=gcnew NetworkCredential("anonymus","my_name@.com");
req_C->Method=WebRequestMethods::Ftp::UploadFile;
req_Wind->Method=WebRequestMethods::Ftp::UploadFile;
FileStream^ c_Stream=gcnew FileStream("InfoC.txt",FileMode::Open);
FileStream^ wind_Stream=gcnew FileStream("InfoWind.txt",FileMode::Open);
Stream^ c_St=req_C->GetRequestStream();
Stream^ wind_St=req_Wind->GetRequestStream();
do
{
value=c_Stream->Read(c_Buf,0,1024);
c_St->Write(c_Buf,0,value);
}while(value!=0);
do
{
value=wind_Stream->Read(wind_Buf,0,1024);
wind_St->Write(wind_Buf,0,value);
}while(value!=0);
 
 

}
private: System::Void button2_Click(System::Object^  sender, System::EventArgs^  e) {
Close();
}
};

Brak komentarzy:

Prześlij komentarz