AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Plugins (https://forums.alliedmods.net/forumdisplay.php?f=108)
-   -   [ANY] tEasyFTP v0.0.2 (2011-12-29) (https://forums.alliedmods.net/showthread.php?t=162910)

Thrawn2 07-24-2011 11:43

[ANY] tEasyFTP v0.0.2 (2011-12-29)
 
4 Attachment(s)
This requires the cURL extension to compile and use!

Currently i've only implemented uploading file(s) to a ftp server, but i might also add some other stuff over time.
This can't be considered stable (yet). Don't trust it. I might even change the natives... you have been warned.

It uses a configuration scheme similar to databases.cfg. It expects a file RemoteTargets.cfg in your config folder that looks like this:
Code:

"RemoteTargets"
{
        "example"
        {
                "host"                "example.com"
                "port"                "21"
                "user"                "ftpuser"
                "password"        "ftppass"
                "path"                "/"
                "ssl"                "try"
               
                "CreateMissingDirs"        "1"               
        }
}

You could then use this native + callback to upload a file to that target:
PHP Code:

functag EasyFTP_FileUploaded public(const String:sTarget[], const String:sLocalFile[], const String:sRemoteFile[], iErrorCodeany:data);
native EasyFTP_UploadFile(const String:sTarget[], const String:sLocalFile[], const String:sRemoteFile[], EasyFTP_FileUploaded:funcany:data 0); 

Example:
PHP Code:

EasyFTP_UploadFile("demos""myDemoFile.dem""/"EasyFTP_CallBack); 

and
PHP Code:

public EasyFTP_CallBack(const String:sTarget[], const String:sLocalFile[], const String:sRemoteFile[], iErrorCodeany:data)
{
    if(
iErrorCode == 0)        // These are the cURL error codes
    
{
        
PrintToServer("Success. File %s uploaded to %s."sLocalFilesTarget);    
    } else {
        
PrintToServer("Failed uploading %s to %s."sLocalFilesTarget);    
    }


This will upload the file myDemoFile.dem to the demos target and report the result using PrintToServer.

Changelog:
Can be found on github.

Some Notes:
  • A target does not need to have a path specification. This is meant for the consumer of your plugin to configure where he wants the files to be put. The remoteFile you are specifying in your code is appended to that path.
  • You can omit leading slashes.
  • If you specify a trailing slash for the remote file, it uses the same basename as the local file.
    For example EasyFTP_UploadFile("demos", "/srcfolder/mydemo.dem", "/asdf/", CallbackFunc); uploads to /asdf/mydemo.dem.
  • This plugin queues your upload commands, so only one file will be transferred at a time and the queues will be processed in the order they appear in the config file - which means files will not necessarily be uploaded in the order you've added them if you are uploading them to different queues.
    This also means that an queue that always has a job in it blocks all following queues, which is a bug i have to fix. As long as you are operating on a single target or only on targets that don't tend to have an upload running all the time, you should be fine.

Known Bugs/Issues
  • I've only tested this with binary transfers, no idea what happens when transfering an ASCII file, but i guess you should be fine.
  • The method this plugin reads binary data is awful, but i couldn't manage to not get 4 byte blocks by ReadFile(). Suggestions are very welcome.

Peace-Maker 12-21-2011 20:16

Re: [ANY] tEasyFTP v0.0.1 (2011-07-24)
 
I'm acutally using this btw. Nice work!
You got some typos in your plugin. (Declaring the UploadFile native without the underscore and missing a ! before FileExists(remotetargets.cfg...)

It's working fine for the binary data i'm using it for even and especially on mapchanges.

More suggestions:
Adding those options in CurlUploadFile
PHP Code:

curl_easy_setopt_int(hCurlCURLOPT_FTP_CREATE_MISSING_DIRSCURLFTP_CREATE_DIR);
curl_easy_setopt_int(hCurlCURLOPT_USE_SSLCURLUSESSL_TRY); 

Supporting a "any:data" parameter in the UploadFile native which just gets added to the hTrie_UploadEntry trie on call and passed to the callback forward.

And that +1 in your getFileBasename function seems out of place. Shouldn't that be inside the []?

McFlurry 12-21-2011 20:51

Re: [ANY] tEasyFTP v0.0.1 (2011-07-24)
 
Ooh, very nice. This looks like something I'll use in the future. Nice work. :D
Edit: Downloading a file from ftp would be very useful.

Thrawn2 12-29-2011 13:56

Re: [ANY] tEasyFTP v0.0.2 (2011-12-29)
 
Updated to 0.0.2
  • Added any:data parameter
  • Added 'ssl' and 'CreateMissingDirs' option to RemoteTargets
  • Fixed other issues reported by Peace-Maker

Edit: Also fixed the missing parameter for the forward.

minimoney1 01-01-2012 18:58

Re: [ANY] tEasyFTP v0.0.2 (2011-12-29)
 
The plugin gives me the error of it being not able to resolve my host name but I can perfectly connect to it through Filezilla.
Sorry for posting twice but I guess this is more related to the FTP part (tEasyFTP) rather than the demo plugin.

Thrawn2 01-01-2012 19:37

Re: [ANY] tEasyFTP v0.0.2 (2011-12-29)
 
Quote:

Originally Posted by minimoney1 (Post 1623381)
The plugin gives me the error of it being not able to resolve my host name but I can perfectly connect to it through Filezilla.

You've started filezilla on your gameserver (via rdp to windows?) and tried connecting to your ftp and that worked fine? Then we have a problem... Or did you use FileZilla on your desktop machine?
I'm assuming the latter :wink: and the next assumption is that your gameserver is rented from some random game server hosting company - they don't allow shell access probably. Might it be possible that they don't allow outgoing connections other than the ones made by the gameserver on its own either? Then it's not this plugins problem :)

If i'm completely on the wrong path here, please correct me with some more details. I'm specifically curious on this: What error does it give when you try it with the IP directly? It probably won't be "can't resolve host" :wink: ?

minimoney1 01-01-2012 21:45

Re: [ANY] tEasyFTP v0.0.2 (2011-12-29)
 
Nope, yes you're right it's rented from a gameserver company, Gameservers.com to be exact.
I've tried using the IP for the host and it gives the same error. The problem also is that even when I try it on SRCDS on my own computer (just for testing purposes), it gives me the same error.
This applies for both having the host field as the IP and the domain.

Peace-Maker 01-05-2012 21:15

Re: [ANY] tEasyFTP v0.0.2 (2011-12-29)
 
Awesome stuff :)

Peace-Maker 01-11-2012 17:01

Re: [ANY] tEasyFTP v0.0.2 (2011-12-29)
 
Uh, i'll check that too ;)
Code:

L 01/10/2012 - 12:43:33: [SM] Native "AddToForward" reported: Plugin handle 6e006e is invalid (error 1)
L 01/10/2012 - 12:43:33: [SM] Displaying call stack trace for plugin "tEasyFTP.smx":
L 01/10/2012 - 12:43:33: [SM]  [0]  Line 302, C:\Users\Jannik\Desktop\Plugins\wcfanplugins\wcfansourcetvmanager\addons\sourcemod\scripting\tEasyFTP.sp::onComplete()

Looks like i reloaded the plugin midupload :O

Thrawn2 01-11-2012 18:45

Re: [ANY] tEasyFTP v0.0.2 (2011-12-29)
 
Quote:

Originally Posted by Peace-Maker (Post 1629724)
Looks like i reloaded the plugin midupload :O

fixed. will be in the next version.
thx for reporting.


All times are GMT -4. The time now is 20:03.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.