Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Extra libraries, Code snippets, applications etc. » U++ users applications in progress and useful code snippets, including reference examples! » Uploading files via FTP
Uploading files via FTP [message #6421] Sat, 11 November 2006 17:58 Go to next message
mirek is currently offline  mirek
Messages: 11991
Registered: November 2005
Ultimate Member
This nice little piece of U++ code is responsible for "syncing" www.ultimatepp.org content:

	Vector<String> upload;
	{
		FindFile ff(AppendFileName(targetdir, "*.*"));
		while(ff) {
			if(ff.IsFile()) {
				String s = LoadFile(AppendFileName(targetdir, ff.GetName()));
				String f = AppendFileName(diffdir, ff.GetName());
				if(LoadFile(f) != s) {
					upload.Add(ff.GetName());
				}
			}
			ff.Next();
		}
	}
	if(upload.GetCount()) {
		Progress pi;
		pi.SetTotal(upload.GetCount());
		FtpClient ftp;
		pi.Create();
		pi.SetText("connecting...");
		if(!ftp.Connect(GetIniKey("UppFtp"), GetIniKey("UppFtpUsr"), GetIniKey("UppFtpPwd"), true)) {
			Exclamation("Unable to connect!" + ftp.GetError());
			return;
		}
		if(!ftp.Cd("www")) {
			Exclamation("Unable to 'cd www'");
			return;
		}
		for(int i = 0; i < upload.GetCount(); i++) {
			pi.SetText(upload[i]);
			if(pi.StepCanceled())
				break;
			String s = LoadFile(AppendFileName(targetdir, upload[i]));
			if(!ftp.Save(GetFileName(upload[i]), s)) {
				Exclamation("FTP error (file upload): " + ftp.GetError());
				return;
			}
			SaveFile(AppendFileName(diffdir, ff.GetName()), s);
		}
	}


Mirek
Re: Uploading files via FTP [message #6610 is a reply to message #6421] Mon, 20 November 2006 20:24 Go to previous messageGo to next message
cioannou is currently offline  cioannou
Messages: 45
Registered: January 2006
Location: Greece
Member
Great, thanks for sharing.

Can you please share some info on the filesystem functions?

Thanks
Re: Uploading files via FTP [message #20014 is a reply to message #6421] Mon, 09 February 2009 22:02 Go to previous messageGo to next message
klrkt is currently offline  klrkt
Messages: 20
Registered: December 2008
Promising Member
nice example - but how can I make it work?
Could you please post a very simple complete project?

I tried the following code in a console, and a window app, and all versions crash IF the ftp.connect is NOT commented out.

Can anyone post a simple complete project? - thank you.

Here is the code:
(YES - I added the plugin/ftp and web stuff...)

#include <plugin/ftp/ftp.h>
#include <plugin/ftp/lib/ftplib.h>
#include <stdio.h>
CONSOLE_APP_MAIN
{
const Vector<String>& cmdline = CommandLine();
for(int i = 0; i < cmdline.GetCount(); i++) {
}
Vector<String> upload;
upload.Add("out.txt");
String strhost="ftp://someftp.com";
String strftpUser="someuser";
String strftpPass="somepassword";
FtpClient ftp;
if(!ftp.Connect(strhost, strftpUser, strftpPass, true)) {
printf("Unable to connect ");
return;
}
}
Re: Uploading files via FTP [message #20015 is a reply to message #20014] Tue, 10 February 2009 00:55 Go to previous messageGo to next message
andrei_natanael is currently offline  andrei_natanael
Messages: 262
Registered: January 2009
Experienced Member
The problem is here:
"ftp://someftp.com";

you're using it incorrect, you shouldn't use "ftp://" URI scheme name because ftp client doesn't understand it. A ftp URI is just an uri like "ftp.someftp.com" or "someftp.com"(without ftp:// scheme), in essence matter just the connection port(a ftp server should listen on it) and protocol(FTP).

[Updated on: Tue, 10 February 2009 00:55]

Report message to a moderator

Re: Uploading files via FTP [message #20020 is a reply to message #20015] Tue, 10 February 2009 16:00 Go to previous message
klrkt is currently offline  klrkt
Messages: 20
Registered: December 2008
Promising Member
Of course you are correct.
Many thanks dude!
Much appreciated.
Previous Topic: Hexbombs
Next Topic: HomeBudget example bug
Goto Forum:
  


Current Time: Sun Aug 18 19:20:23 CEST 2019

Total time taken to generate the page: 0.00715 seconds