Загрузка на FTP-сервер

Я работаю над крошечным крошечным приложением, которое просто загружает файл на FTP-сервер. Я проверил свой код, но я вполне не в состоянии найти проблему. Вот код,

#include "stdafx.h"

using namespace System;

#include "iostream"
#include <conio.h>

using namespace System;

void UploadFiles(String ^_FileName, String ^_UploadPath, String ^_FTPUser, String ^_FTPPass);

int main ()
{
    // Upload file using FTP
    UploadFiles("c:\\test.html", "ftp://playbabe.tk/public_html/test.html", "xxxxxx", "xxxxxx");
    return 0;
}

void UploadFiles(System::String ^_FileName, System::String ^_UploadPath, System::String ^_FTPUser, System::String ^_FTPPass)
{
    System::IO::FileInfo ^_FileInfo = gcnew System::IO::FileInfo(_FileName);

    // Create FtpWebRequest object from the Uri provided
    System::Net::FtpWebRequest ^_FtpWebRequest = safe_cast<System::Net::FtpWebRequest^>(System::Net::FtpWebRequest::Create(gcnew Uri(_UploadPath)));

    // Provide the WebPermission Credintials
    _FtpWebRequest->Credentials = gcnew System::Net::NetworkCredential(_FTPUser, _FTPPass);

    // By default KeepAlive is true, where the control connection is not closed
    // after a command is executed.
    _FtpWebRequest->KeepAlive = false;

    // set timeout for 20 seconds
    _FtpWebRequest->Timeout = 20000;

    // Specify the command to be executed.

    _FtpWebRequest->Method =System::Net::WebRequestMethods::Ftp.UploadFile;

    // Specify the data transfer type.
    _FtpWebRequest->UseBinary = true;

    // Notify the server about the size of the uploaded file
    _FtpWebRequest->ContentLength = _FileInfo->Length;

    // The buffer size is set to 2kb
    int buffLength = 2048;
    array<System::Byte> ^buff = gcnew array<System::Byte>(buffLength);

    // Opens a file stream (System.IO.FileStream) to read the file to be uploaded
    System::IO::FileStream ^_FileStream = _FileInfo->OpenRead();

    try
    {
        // Stream to which the file to be upload is written
        System::IO::Stream ^_Stream = _FtpWebRequest->GetRequestStream();

        // Read from the file stream 2kb at a time
        int contentLen = _FileStream->Read(buff, 0, buffLength);

        // Till Stream content ends
        while (contentLen != 0)
        {
            // Write Content from the file stream to the FTP Upload Stream
            _Stream->Write(buff, 0, contentLen);
            contentLen = _FileStream->Read(buff, 0, buffLength);
        }

        // Close the file stream and the Request Stream
        _Stream->Close();
        delete _Stream;
        _FileStream->Close();
        delete _FileStream;
    }
    catch (Exception ^ex)
    {
        //MessageBox::Show(ex->Message, "Upload Error", MessageBoxButtons::OK, MessageBoxIcon::Error);
        std::cout<<"error";
    }

    getch();
}

дает два ошибки в Visual C ++ 2010 Express,

Ошибка 1 Ошибка C2275: Система :: Net :: WebRequestMeths :: FTP ': Незаконное использование этого типа Как выражение C: \ Users \ Me \ Me \ Documents \ Visual Studio 2010 \ Projections \ Test1 \ Test1 \ Test1.cpp 70

Ошибка 2 Ошибка C2228: Слева от . UploadFile ' должен иметь класс / Struction / Union C: \ Users \ Me \ Documents \ Visual Studio 2010 \ Projects \ Test1 \ Test1 \ Test1.cpp 70

Я не уверен, что здесь не так.

-8
задан Peter Mortensen 24 January 2012 в 19:36
поделиться