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.

• Valestrom
2
Contributors
3
Replies
4
Views
5 Years
Discussion Span
Last Post by thines01

What compiler and OS are you using for the client?

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

Edited by valestrom

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

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

try
{
WebClient^ webClient = gcnew WebClient();
}
catch (WebException^ excWeb)
{
strError = excWeb->Message;
blnRetVal = false;
}

return blnRetVal;
}

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

if(!SendToDest(
"anonymous",   // USER
"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 topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.