I have succeded to connect to the ftp server and also the file that I want to read like this. That was really nice
I also succeded to read the lines from the file. Then I am trying to write lines to the file but here I get an errormessage:
Code:
The stream is not writable
However I have red something about EnableSsl = true
"Unless the EnableSsl property is true, all data and commands, including your user name and password information, are sent to the server in clear text. Anyone monitoring network traffic can view your credentials and use them to connect to the server."
The thing is that it will be users connecting to the ftp.server and what I am afraid for is that any "hackers" might see what "User" and "Password" there is. I dont really know so much about any securitys for this.
Code:
//First a request to FTP Server shall be initiated, requesting the file needed.
String^ FilePath = "ftp://myWebsite.info:21/MyFolder/MyFile.txt";
FtpWebRequest^ objRequest = (FtpWebRequest^)WebRequest::Create(FilePath);
objRequest->Credentials = gcnew NetworkCredential("User", "Password");
//Then, we have to get the response for this request:
FtpWebResponse ^objResponse = (FtpWebResponse^) objRequest->GetResponse();
//Get the stream
Stream^ responseStream = objResponse->GetResponseStream();
//read the file;
List<String^> Lines = gcnew List<String^>();
StreamReader^ reader = gcnew StreamReader(responseStream);
while( reader->Peek() >= 0 )
{
Lines.Add(reader->ReadLine()); //Save all Lines;
}
//Lets close Everything
reader->Close();
//Write something to file for test
StreamWriter^ writer = gcnew StreamWriter(responseStream);
for( int i = 0; i < 5; i++ )
{
writer->WriteLine("SomeLines"); //This gives an errormessage telling that the stream is not writable
}
writer->Close();
responseStream->Close(); //close the stream after reading;
objResponse->Close(); //Closes the connection to the server;