Article:
 |
|
Building FTP Services Using .NET 2.0
|
| Subject: |
|
Example for .NET C++ |
| Date: |
|
2007-09-09 07:07:29 |
| From: |
|
aghochikayn
|
|
|
try
{
Stream^ requestStream = nullptr;
FileStream^ fileStream = nullptr;
FtpWebResponse^ uploadResponse = nullptr;
FileInfo^ info = gcnew FileInfo(strPath);
FtpWebRequest^ uploadRequest = (FtpWebRequest^)WebRequest::Create(strFtpUri);
uploadRequest->Credentials = gcnew NetworkCredential(strUserName,strPassword);
uploadRequest->UsePassive = false;
uploadRequest->KeepAlive = false;
uploadRequest->Method = WebRequestMethods::Ftp::UploadFile;
uploadRequest->UseBinary = true;
uploadRequest->ContentLength = info->Length;
requestStream = uploadRequest->GetRequestStream();
fileStream = info->OpenRead();
uploadRequest->ContentLength = fileStream->Length;
array<Byte>^ buffer = gcnew array<Byte>(1024);
int bytesRead;
while (true)
{
bytesRead = fileStream->Read(buffer, 0, buffer->Length);
if (bytesRead == 0)
break;
requestStream->Write(buffer, 0, bytesRead);
}
fileStream->Close();
requestStream->Close();
uploadResponse = (FtpWebResponse^)uploadRequest->GetResponse();
MessageBox::Show(uploadResponse->StatusDescription);
}
catch(System::Exception^ e)
{
MessageBox::Show(e->Message);
}
Visit our site: Emergency Soft (http://www.emergencysoft.com)
|
Showing messages 1 through 1 of 1.
-
Example for .NET C++
2008-11-23 12:44:08
Stefan W
[View]
The requested URI is invalid for this FTP command.
why?