Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6561323
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:34:21+00:00 2026-05-25T13:34:21+00:00

I am working on a tiny tiny application that just uploads a file to

  • 0

I am working on a tiny tiny application that just uploads a file to the FTP server. I have reviewed my code, but I am quite unable to locate the problem. Here is the code,

#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();
}

It gives two errors in Visual C++ 2010 Express,

Error 1 error C2275: 'System::Net::WebRequestMethods::Ftp' : illegal use of this type as an expression C:\Users\Me\documents\visual studio 2010\Projects\test1\test1\test1.cpp 70

Error 2 error C2228: left of '.UploadFile' must have class/struct/union C:\Users\Me\documents\visual studio 2010\Projects\test1\test1\test1.cpp 70

I am not sure what is going wrong here.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T13:34:21+00:00Added an answer on May 25, 2026 at 1:34 pm

    I don’t know C++/CLI, but the following statement is certainly wrong:

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

    System::Net::WebRequestMethods::Ftp is a type and, as the error message indicates (you could have given us the line number!) you’re trying to use it as an expression.

    Are you trying to obtain a pointer to a static member function?

    Did you thus mean the following?

    _FtpWebRequest->Method = System::Net::WebRequestMethods::Ftp::UploadFile;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on an application that uploads a file to amazon s3(part of
I'm working on my C# client server application for school, and I have a
I'm working in tiny project that deal with multiple file uploading. at the begining
I'm working on an application that generates a large number of Google Map markers
I have this working ok(ish) in my game at the moment, but i'm not
I'm working with fancybox and I have the code below: <script type=text/javascript> $(a#next_fancybox).fancybox(); </script>
For the project I'm working on, we have a desktop program that contacts an
I am working on an ASP.Net web application that must print dynamically created labels
I have a class file that contains all the classes that are needed for
Hey guys and girls. I have a method that creates rain particles, tiny images,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.