ftp_download

Posted By: DLively

ftp_download - 04/24/15 06:24

There isn't much documentation in the manual about this. I tried to use the example with my own credentials, and it doesnt work, although Im certain it should.

Im entering the same info id use to log into filezilla.
Can you please help me in the right direction?

Code:
ftp_download("ftp//:www.host.com/model.mdl", "models/model.mdl", "USER", "PASSWORD");

	while (!ftp_status()) //as long as the download is running
	{ //get informations about the download:
		fsize = ftp_size();
		fsent = ftp_sent();
		wait(1);
	} 
	if (ftp_status() == 1) 
	printf("Download successful!"); 
	else 
	printf("Error during download!");



Thank you for your time.
Posted By: jcl

Re: ftp_download - 04/24/15 10:48

I see a syntax error in the URL, and also I'm suspicious about "models/model.mdl" - better give an absolute path.
Posted By: DLively

Re: ftp_download - 04/24/15 12:56

Thanks for your reply Jcl,

yeah.. [face palm] I noticed the Url was wrong after I posted my question.. I thought I updated that.

I tried using an absolute path, and with no luck im still getting "error during download"
ftp_size becomes -1, and ftp_sent stays at 0.

Here is the updated code:
Code:
#define ADDRESS "ftp://www.host.com/model.mdl"
#define _PATH "E:/projectfolder/models/model.mdl"
#define USER "filezilla_user"
#define PASS "filezilla_pass"

void update_game(){
	ftp_debug(1);

	ftp_download(ADDRESS, _PATH, USER, PASS);
	while (!ftp_status()) //as long as the download is running
	{ //get informations about the download:
		fsize = ftp_size();
		fsent = ftp_sent();
		DEBUG_VAR(fsize, 100);
		DEBUG_VAR(fsent, 120);
		wait(1);
	} 
	if (ftp_status() == 1) 
	printf("Download successful!"); 
	else 
	printf("Error during download!"); 
}

function main(){

	update_game();
	wait_for(update_game);
        ...
}

Posted By: DLively

Re: ftp_download - 04/24/15 13:08

Just a quick update.

I have access to two servers, and with their proper credentials entered, neither one produce any more or less of a result.
Posted By: DLively

Re: ftp_download - 04/24/15 13:17

I got the ftp_log to work, however there is content that I trust only in your Pm's...

Pm sent laugh
Posted By: jcl

Re: ftp_download - 04/24/15 16:21

Better contact Support - as a Pro user you have 12 months support. I suspect that the problem might be related to the folder structure or usage rights of your ftp server, but the support can look into your logs and tell you for sure.
Posted By: DLively

Re: ftp_download - 04/24/15 17:07

Unfortunately, I purchased my Professional Licence Used -- Furthermore, I purchased it used over a year ago.

Both ftp logs are the same -> Everything works fine and its connecting to the server, however it appears that it is having trouble downloading the file I am requesting, because it does register that I am looking for the entered file. But apparently it can't find that file..


Code:
> TYPE I

< 200 TYPE is now 8-bit binary

> SIZE hero.mdl

< 550 Can't check for file existence

> RETR hero.mdl

< 550 Can't open hero.mdl: No such file or directory

* RETR response: 550
* Remembering we are in dir ""
* Connection #0 to host www.devonlively.com left intact
* Remote file not found
> QUIT

< 221-Goodbye. You uploaded 0 and downloaded 0 kbytes.

< 221 Logout.

* Closing connection #0



Hopefully Someone can fill in the blanks from here for me..
Posted By: Ch40zzC0d3r

Re: ftp_download - 04/24/15 23:09

Stop using 3DGS stuff and use WinAPI combined with Winsock2.
Takes 10 mins to implement it to a new project and add it as plugin to your game. Google is full of results on how to download a file with it from a remote server
Posted By: DLively

Re: ftp_download - 04/25/15 05:32

can you recommend a tutorial for me to start with? Im looking, and Im learning, but it would be nice to be turned in the right direction, as i feel I am walking around with a blindfold on...
Posted By: DLively

Re: ftp_download - 04/25/15 05:42

Code:
////////////////////////////////////////////////////////////////////////////////
// lite-c header for http / ftp functions
// (c) 2009 Peter Soxberger / oP group Germany
////////////////////////////////////////////////////////////////////////////////

#ifndef ACKNET_H
#define ACKNET_H

#define PRAGMA_BIND "acknet.dll";

var http_proxy(char* proxy,var port);

var http_sendpost(char* url, char* data);

var http_status(var httpid);

var http_result(var httpid, STRING* result);

var http_free(var httpid);


var ftp_download(char* url, char* path, char* username, char* password);

var ftp_upload(char* url, char* path, char* username, char* password);

var ftp_getdate(char* url, char* username, char* password);

void ftp_stop();

long ftp_size();

long ftp_sent();

long ftp_timestamp();

var ftp_status();

var ftp_debug(var mode);

#endif



How is this being taken from the dll?
// - using this as an example, I don't understand.
Code:
public class HttpRemoteDownload : RemoteDownload
    {
        public HttpRemoteDownload(string urlString, string descFilePath)
            : base(urlString, descFilePath)
        {
 
        }
 
        public override bool DownloadFile()
        {
            string fileName = System.IO.Path.GetFileName(this.UrlString);
            string descFilePathAndName =
                System.IO.Path.Combine(this.DescFilePath, fileName);
            try
            {
                WebRequest myre = WebRequest.Create(this.UrlString);
            }
            catch
            {
                return false;
            }
            try
            {
                byte[] fileData;
                using (WebClient client = new WebClient())
                {
                    fileData = client.DownloadData(this.UrlString);
                }
                using (FileStream fs =
                      new FileStream(descFilePathAndName, FileMode.OpenOrCreate))
                {
                    fs.Write(fileData, 0, fileData.Length);
                }
                return true;
            }
            catch (Exception ex)
            {
                throw new Exception("download field", ex.InnerException);
            }
        }
    }
 
public class FtpRemoteDownload : RemoteDownload
    {
        public FtpRemoteDownload(string urlString, string descFilePath)
            : base(urlString, descFilePath)
        {
 
        }
 
        public override bool DownloadFile()
        {
            FtpWebRequest reqFTP;
 
            string fileName = System.IO.Path.GetFileName(this.UrlString);
            string descFilePathAndName =
                System.IO.Path.Combine(this.DescFilePath, fileName);
 
            try
            {
 
                reqFTP = (FtpWebRequest)FtpWebRequest.Create(this.UrlString);
                reqFTP.Method = WebRequestMethods.Ftp.DownloadFile;
                reqFTP.UseBinary = true;
                
 
                using (FileStream outputStream = new FileStream(descFilePathAndName, FileMode.OpenOrCreate))
                using (FtpWebResponse response = (FtpWebResponse)reqFTP.GetResponse())
                using (Stream ftpStream = response.GetResponseStream())
                {
                    int bufferSize = 2048;
                    int readCount;
                    byte[] buffer = new byte[bufferSize];
                    readCount = ftpStream.Read(buffer, 0, bufferSize);
                    while (readCount > 0)
                    {
                        outputStream.Write(buffer, 0, readCount);
                        readCount = ftpStream.Read(buffer, 0, bufferSize);
                    }
                }
                return true;
            }
 
            catch (Exception ex)
            {
                throw new Exception("upload failed", ex.InnerException);
            }
        }
    }

Posted By: FBL

Re: ftp_download - 04/25/15 07:47

Your script is working fine for me.

Quote:

(...)
ftp_download("ftp://www.firoball.de/www/download/4lw.zip", "4lw.zip", "fd-lgkjsröog", "sfkjheifgrelkf");
(...)


Most likely you're missing the www base directory in your path.
Quote:
* Remembering we are in dir ""
Posted By: DLively

Re: ftp_download - 04/25/15 15:48

Wow.. Really. Thats it?
Thats all I was missing...

That said.. All Hail Firoball laugh
You'd think that the developers would have had this solution.. Perhaps putting it into the manual for future seekers would be beneficial.

Now that it works, What security breaches does this cause? How can I properly make use of this as to not compromise my websites security?

#Happy.
Posted By: FBL

Re: ftp_download - 04/25/15 16:59

FTP in general is not really safe. And since you'll have the account data somewhere in your project, there's nothing like safety.
One thing you can do is having a user setup which is only allowed to read (download) files, and only has access to a single folder (maybe + subfolders) where you put all the download stuff.
If someone messes with that account, you'll get more download traffic, but you don't have to fear about unwanted upload/deletions.
-> never give away your "administrator" account

Maybe you can even get some server only responsible for providing downloadable stuff, so in case something happens with it, nothing else is affected.

I'm pretty sure justsid can tell you more about security issues, what I wrote is the bare minimum you can and should do.

Concerning the default folder: it usually is www - for web stuff. But this is not required, it can be anything. Basically you should use a ftp client and log in first, then see where you start - which you usually anyway do when you upload the file for later download. From there on you can trace the full required path. Just taking the web address and replacing http:// with ftp:// will not work, as your www-domain normally does not point to the ftp user's home directory.
Posted By: WretchedSid

Re: ftp_download - 04/25/15 20:04

Originally Posted By: Firoball
I'm pretty sure justsid can tell you more about security issues, what I wrote is the bare minimum you can and should do.

You know, I really wanted to from the get go of the thread but kept my mouth shut, but...

Originally Posted By: DLively
Now that it works, What security breaches does this cause?

All of them! You are putting both your server and your client at risk. As Firo mentioned, you are putting the credentials of your server into a binary that ships to your customers. So the customer can basically do whatever they want. You can try to combat that by constraining the user rights, but that's error prone and you are still doing something you ideally don't want to do at all. Basically the risk you are getting into here is that your ftp server becomes an anonymous drop for warez and porn, as well as kiddies just emptying out your server. If you like both waren and porn and aren't afraid of law enforcement, this is the way to go.

And then there is the client. FTP is not a secure connection, so it's prone to very easy man in the middle attacks. It'd be trivial to get the client to download data it never wanted to and there would be no way for you to verify the authenticity of the data. Getting a client to download arbitrary data and potentially even executing that with the permissions of your game (potentially admin rights, woop woop) is... Well, maybe not exactly what you want to happen.

The ideal way to go for this is to use a secure connection. HTTPS in particular. Since you know exactly what server you will talk to, you can easily (and definitely should!) pin the server certificate on the client and verify that you are really talking to your server.
Out of the box, Gamestudio does not not provide methods to either open an HTTPS connection nor does it provide methods for certificate pinning. You would need a DLL for that.
Posted By: DLively

Re: ftp_download - 04/25/15 21:18

Thanks Firoball laugh That really helps clear up why things were not working for me.. now that it does, it makes sense why it didn't...

Thank you Sid, I love reading your informations. Always a fun read. So basically just scrap everything I thought was right, and go back to square 1 where everyone has been telling me to start back at since the first time I asked this question...

So, dlls... face palm. For some reason Im having a tough time figuring these out..

Any good tutorials on combining VC++ with gstudio for a basic dll function?
Posted By: Reconnoiter

Re: ftp_download - 04/25/15 22:23

Quote:
If you like both waren and porn and aren't afraid of law enforcement, this is the way to go.
, this line cracked me open grin

Quick question; are gs3d's http and sockets functions somewhat secure?
Posted By: FBL

Re: ftp_download - 04/25/15 23:16

http is not secure either. As with ftp it's not acknex which is the problem, it's the protocol.
Posted By: Reconnoiter

Re: ftp_download - 04/26/15 09:53

Tnx for letting me know
Posted By: DLively

Re: ftp_download - 04/26/15 12:49

So why is a dll more secure? or is it even? Because I can download software to open a dll, and then just find security information that way..
Posted By: WretchedSid

Re: ftp_download - 04/26/15 18:07

Originally Posted By: Reconnoiter
Quick question; are gs3d's http and sockets functions somewhat secure?

To tag on to what Firo said, sockets aren't inherently secure either. But protocols on top of sockets can be secure, like for example HTTPS and SFTP.

Originally Posted By: DLively
So why is a dll more secure? or is it even? Because I can download software to open a dll, and then just find security information that way..

A DLL is not secure. That's not why you should use a DLL. You should use a DLL to use a secure protocol to get the data, namely HTTPS, because this functionality can't be found in Gamestudio. HTTPS does not require credentials that you have to put in the DLL, but HTTPS provides you with means to be sure that data is not tampered with. And, again, use certificate pinning to pin the server certificate. Otherwise, if you just accept any valid certificate, you are still suspicable to man in the middle attacks. And of course on the plus side, since you are no longer relying on the chain of trust to trust your server, you can use a self signed certificate which saves you a couple of bucks.
Posted By: DLively

Re: ftp_download - 04/26/15 22:37

Oh how I wish I had your knowledge written in one book... or a few. Either way grin

Anyway, This really helped me. I now know to stay away from FTP and SFTP then, because one of those would have been my original method... I was trying to find a tutorial on how to set up sftp into a dll actually.


So, I'm gunna take all your keywords and google them up.
I'm currently looking into how to just create a dll to do anything with 3dgs -- like litterally anything at all. Start small and build on from there.

I can program with php (to some extent -- like I can build a basic forum if I wanted) So I think that should be sufficient knowledge for that end of programming, right? Also need to look into making a self signed certificate... Tons to look into....

Cheers Sid,
You Rock!




Once again, any tutorial that leads me in the right direction will be cool laugh

Edit: Which VC++ version should I have installed?
Posted By: WretchedSid

Re: ftp_download - 04/27/15 00:15

Originally Posted By: DLively
Edit: Which VC++ version should I have installed?

I'm going to lean myself out of the metaphorical window here, but I think you can choose whichever you want as long as you stay away from the engine SDK. If you stick to a C interface, and it's not like you actually have a choice here, the produced DLL should be ABI compatible with Lite-C.

The basic idea of a DLL is that you have code compiled into a different binary that is loaded at runtime and then linked at runtime. Normally when you write a function in Lite-C and then later call it, the target address is resolved when you compile your application. The difference with a DLL is that the target address is resolved at runtime, which means you have to import the functions from the DLL which will tell the compiler that the function does actually exist and is okay to call, it just is not visible yet, but it also puts an entry into your binary so the dynamic linker can load the DLL and resolve the targets for you at runtime.

Let's say your DLL exports a function called foobar which takes an int, you would then declare the function on the Lite-C side like this:

Code:
void foobar(int bar);
#define PRAGMA_API foobar;myDLL!foobar



You can also rename the function if you would like, the first part of PRAGMA_API is the identifier of the function in Lite-C, then comes the name of your DLL and then comes the identifier of the exported function.

Your callsites don't change, it still looks like this
Code:
foobar(42); // Call into the DLL

Posted By: DLively

Re: ftp_download - 04/27/15 01:19

Code:
#ifndef ACKNET_H
#define ACKNET_H

#define PRAGMA_BIND "acknet.dll";

var http_proxy(char* proxy,var port);

var http_sendpost(char* url, char* data);

var http_status(var httpid);

var http_result(var httpid, STRING* result);

var http_free(var httpid);


var ftp_download(char* url, char* path, char* username, char* password);

var ftp_upload(char* url, char* path, char* username, char* password);

var ftp_getdate(char* url, char* username, char* password);

void ftp_stop();

long ftp_size();

long ftp_sent();

long ftp_timestamp();

var ftp_status();

var ftp_debug(var mode);

#endif



I was Basing my original idea of how things are constructed with the above code. Is the dll I create being declared differently than this one?


I just dont understand how to put stuff into my dll.. I looked up a tutorial and came up with this:

.cpp file
Code:
#include <iostream>
using namespace std;
#include "SimpleHeader.h"

namespace nmspace
{
	void myclass::Crap()
	{
		cout << "I'm called within a crappy DLL!";
	}
}



and a dot.h file
Code:
namespace nmspace
{
	class myclass
	{
	public:
		static __declspec(dllexport) void Crap();
	};
}



I then built this and now have a dll (SimpleDll.dll).. how can I use it in 3dgs, so it displays that message?(as a test)


EDIT:
Inside header file mydll.h

void Crap();
#define PRAGMA_API Crap;SimpleDll!Crap

I tried the above, but it said that it can't find crap.. But it initialized the dll grin

Posted By: WretchedSid

Re: ftp_download - 04/27/15 02:12

You are exporting a C++ function, which is subject to name mangling. You want to export a C function which is not subject to name mangling. You can either do that by wrapping your class (which is totally useless as is by the way), or by not even doing that to begin with.

Your cpp file:
Code:
#include <iostream>

extern "C" __declspec(dllexport) void Crap();

void Crap()
{
   std::cout << "Hello world" << std::endl;
}



Please, since you are starting to touch C++, never even start getting used to "using namespace xyz", since it defeats all purposes namespaces have. Also note that "cout" will write to stdout (which in its normal form doesn't even exist on Windows), and you won't see the output of it ever. If you just want to know wether it works, maybe try this:

Code:
#include <iostream>

extern "C" __declspec(dllexport) int FancyMultiply(int a, int b);

int FancyMultiply(int a, int b)
{
   return a * b;
}




Lite-C
Code:
int FancyMultiply(int a, int b);
#define PRAGMA_API FancyMultiply;SimpleDll!FancyMultiply

void main()
{
   printf("8 * 24 = %d", FancyMultiply(8, 24)); 
}

Posted By: DLively

Re: ftp_download - 04/27/15 02:33

Okay, things are starting to come together in my head now.. Roads are being mapped out grin

Though, When I try to use the new dll, 3dgs_dll, It doesn't show up in the compiler -- But I don't get an error or empty function error message so its working to some degree.. will it, or should it appear in the compiler?

This doesn't seem to work for me smirk

Code:
printf("8 * 24 = %d", FancyMultiply(8, 24));



I only get the first half of the printf (the string)




also i tried this:

Code:
DEBUG_VAR(FancyMultiply(8, 24), 100);





EDIT:

NVM. I forgot the fucking while loop around the DEBUG_VAR... IT WORKS!!!!! grin grin grin

OMG! Thank you sooo much Sid, You fucking rock laugh laugh laugh laugh laugh laugh laugh


Quote:

HTTPS does not require credentials that you have to put in the DLL, but HTTPS provides you with means to be sure that data is not tampered with. And, again, use certificate pinning to pin the server certificate. Otherwise, if you just accept any valid certificate, you are still suspicable to man in the middle attacks. And of course on the plus side, since you are no longer relying on the chain of trust to trust your server, you can use a self signed certificate which saves you a couple of bucks.


Any tips on where to start with this? laugh

would you recomend this: http://www.akadia.com/services/ssh_test_certificate.html
Posted By: FBL

Re: ftp_download - 04/27/15 18:18

A certificate can be generated with openssl. If you have a local Apache running, chances are high, you already have it somewhere.

I used the very same tutorial some months ago and it worked fine.

Just do this step by step. No need to really understand anything of this for now. In the end you will have your own certificate, and if you setup your webserver to use it, wou'll get a warning because it's not registered. But this will be fine for your use.
Posted By: WretchedSid

Re: ftp_download - 04/27/15 22:25

Originally Posted By: Firoball
In the end you will have your own certificate, and if you setup your webserver to use it, wou'll get a warning because it's not registered.


It's not because it's not registered but because no sane browser will trust it. Certificates rely on trust, which means that your browser and OS have a couple of certificates they trust, these are called root certificates. Now, normally you get a certificate from a CA (certificate authority) which either has one of these root certificates or a certificate that is signed by a root certificate, they will sign your certificate with their certificate. In the end, you will end up with a chain of trust. Your browser will trust your certificate because it trusts who signed it, or it trusts who signed their certificate, or who signed their certificate. In theory it can be arbitrary long, but for example if you receive a certificate from a CA it won't have the right to sign other certificates.

The idea behind this is that no one can run around and just generate a certificate for let's say google.com. Google has a certificate which was signed by the Google Internet Authority G2, which is an intermediate CA. Their certificate comes from GeoTrust, one of the largest root CAs. If you want a regular certificate, you will have to prove to the CA that you own the domain, only then they will issue you a certificate (and take quite a buck for it).

Now, all this is well and good, the only issue is that is a huge clusterfuck since it relies on trust and trust alone. If you break into a CA and steal their certificate, you can generate your own valid certificate for google.com. So the idea is to limit the amount of CAs that are trusted, but for example both Windows and OS X ship trusting the chinese government and various intelligence agencies who may or may not have an interest in creating fake certificates so your browser trusts their man in the middle attack. Of course, if you were to actually break into a CA, you can be damn sure that their certificate would be revoked and you may actually end up achieving getting their certificate kicked out of the trust store of browsers and operating systems

And this finally is where certificate pinning comes into play. Certificate pinning means that you know what certificate the other end has, and when the server presents you their certificate, instead of just using the chain of trust to verify that the certificate is legit, you also check wether the certificate is the one you would expect it to be. Google does that in Chrome with google.com domains and a couple of others (in fact, there is a registry for that, where companies can register their certificates). If you visit google.com and someone in the middle presents a certificate that is valid but not the correct one, Chrome will give you a warning.

Of course, this is perfect for you! You don't want to rely on trust, because then you would also need to sleep with a CA, you know exactly what server you expect to see and how the certificate will look like. So, you pin it. Doesn't matter if a browser doesn't trust it, all that matters is that you trust it.

How to implement that... Well, since I'm far from being a Windows developer and haven't seriously touched a Windows machine in ages, I have no idea whatsoever. But I would be surprised if C# wouldn't have high level constructs for doing that and I would also be surprised if there wasn't a way to write a C wrapper over that.


Edit: Also, looking at your printf, it already looked like it was working fine? That was exactly the output to expect, or am I missing something?
Posted By: DLively

Re: ftp_download - 04/28/15 09:37

Okay thanks Firo, I'll look into that for sure then laugh

Hmm.. So what If I just bought a cheap ssl cert from a CA that offers them for say 5 dollars yearly - would that be sufficient?

What If I have people going to my website on a daily basis? they will get a trust warning wont they? That is if I create my own ssl cert.

I appreciate all the info and help you've given me to this point, I'll gladly read more grin
You must laugh at us windows users, huh SID? tongue
But seriously, Im gunna dig deep into things. I found lots of information about it in the manual laugh I read every single entry in that damn thing today... Very good read grin Gunna have to do it again soon.

Also, the printf actually does work, but Im still learning -- so mistakes are imminent laugh
Posted By: FBL

Re: ftp_download - 04/28/15 19:09

The warning is just if you try this with your webserver and access with a regular browser. I wrote that part too short tongue

However I think Google has an answer for sure. (1st shot: http://stackoverflow.com/questions/25125165/certificate-pinning-with-winhttp-api ...whatever winhttp is, it sounds possibly useful)
Posted By: DLively

Re: ftp_download - 04/28/15 21:28

I have a website devonlively.com that I want people to visit -- If I they view my website in a regular browser they will get the error message, right?

Thank you for that link, Firo! I skimmed the question and it appears that will take me to the next step with this (hopefully)

Thanks a lot laugh
Ps. I keep seeing your avatar and wanted to mention that Super Ghost and Ghouls was a favorite SNES game of my childhood too laugh
Posted By: FBL

Re: ftp_download - 04/28/15 22:04

Only if you serve SSL (HTTPS). Regular HTTP is not affected.
Posted By: DLively

Re: ftp_download - 04/29/15 08:46

Cool laugh Good to know!
© 2024 lite-C Forums