I was wondering how to Connect to a FTP server in the form of it having Address, Username, and Password. Then be able to either edit or upload a file to a specific folder on the server. Because I am designing a website with a current news box on it and I would like to be able to not have to use my FTP program every time to change one file.

Summary: Connect to FTP with Address Username Password, and write to a file in a speicifc folder on that server.

Thanks ahead of time

  • Valestrom

I'd be using windows vista/7 with Visual C++ 2010

Edited 4 Years Ago by valestrom

You could start with a CLR app that works like this:

#include "stdafx.h"
using namespace System;
using namespace System::Net;

bool SendToDest(
         String^ strUser,
         String^ strPassword,
         String^ strServer,
         String^ strLocalName,
         String^ strRemoteName,
         String^% strError)
{
   bool blnRetVal = true;

   try
   {
      WebClient^ webClient = gcnew WebClient();
      webClient->Credentials = gcnew NetworkCredential(strUser, strPassword);
      webClient->UploadFile(strServer + strRemoteName, strLocalName);
   }
   catch (WebException^ excWeb)
   {
      strError = excWeb->Message;
      blnRetVal = false;
   }

   return blnRetVal;
}

int main(array<System::String ^> ^args)
{
   String^ strError = "";

   if(!SendToDest(
      "anonymous",   // USER
      "dani@web.com",// PASSWORD
      "ftp://SampleServerName/DaniWeb/",
      "c:\\science\\text1.txt",
      "text1.txt", 
      strError
      ))
   {
      Console::WriteLine("Could not send file to server: " + strError);
      return -1;
   }

   Console::WriteLine("Done");

   return 0;
}

Using the WebClient class for simple transfers is easy and concise.

This article has been dead for over six months. Start a new discussion instead.