FTP Plugin v0.2a -
Scottas - 05.08.2011
FTP Plugin v0.2a
About
This is a FTP plugin, which let's you to connect to FTP server and do some operations there.
Update v0.2a
Now functions 'Ftp_PutFile' and 'Ftp_GetFile' downloads or uploads files in another thread, so your server wont be frozen, when downloading or uploading. Currently, you can upload only one file ( you need to wait untill files are sent, to start another upload ), same with download.
Added two callbacks:
Code:
forward OnFtpFileSent ( remotefile [ ], localfile [ ] );
forward OnFtpFileReceived ( remotefile [ ], localfile [ ] );
Functions
Code:
native Ftp_Connect(server[], username[], password[]);
native Ftp_CreateDirectory(directory[]);
native Ftp_DeleteFile(file[]);
native Ftp_GetFile(remote_file[],local_file[],bool:owerwrite);
native Ftp_PutFile(remote_file[],local_file[]);
native Ftp_RemoveDirectory(directory[]);
native Ftp_RenameFile(file_name[],new_file_name[]);
native Ftp_Close(/*No parameters*/);
native Ftp_OpenFile(file[],access);
native Ftp_ReadFile(handle,buff[],size=sizeof(buff));
native Ftp_WriteFile(handle,string[],size=sizeof(string));
native Ftp_CloseFile(handle);
native Ftp_FileExists(file[]);
Example:
pawn Code:
public OnGameModeInit ( )
{
new
var;
// Let's connect to FTP server
var = Ftp_Connect ( "serverip", "username", "password" );
if ( !var )
print ( "Can't connect to FTP server" );
// Create directory in FTP root catalog
var = Ftp_CreateDirectory ( "Dir" );
if ( !var )
print ( "Can't create directory" );
// Create another directory, inside it
Ftp_CreateDirectory ( "Dir/New" );
// Create file in it
var = Ftp_OpenFile ( "Dir/New/newfile.txt", FTP_WRITE );
// Let's write something inside it. If file already exists,
// it will be cleared.
Ftp_WriteFile ( var, "This is first line\n" );
Ftp_WriteFile ( var, "This is second line\n" );
// Let's close this file, it's enough
Ftp_CloseFile ( var );
// Now, you can download it to your server.
// We will use 'Ftp_GetFile' function.
// remote_file[] - is the file, we have created
// local_file[] - is new file on our server,
// which contains remote_file content
var = Ftp_GetFile ( "Dir/New/newfile.txt", "scriptfiles/ournewfile.txt", true );
// Note: If you use 'true' in third param, it will overwrite
// file, if it already exists. If you use 'false', file not gonna be
// downloaded, if it exists on local machine
if ( var )
print ( "File prepared for download" );
// Lets delete file from FTP server, we don't need it anymore
var = Ftp_DeleteFile ( "Dir/New/newfile.txt" );
if ( var )
print ( "File successfully removed" );
// And delete 'New' directory
var = Ftp_RemoveDirectory ( "Dir/New" );
if ( var )
print ( "Directory successfully removed" );
// Now let's upload something
var = Ftp_PutFile ( "Dir/uploaded_file.txt", "pawno/include/ftp.inc" );
if ( var )
print ( "file prepared to upload" );
// Let's open our file, but this time for reading
var = Ftp_OpenFile ( "Dir/uploaded_file.txt", FTP_READ );
// Let's read it
new
line [ 100 ];
while ( Ftp_ReadFile ( var, line ) )
print ( line );
// Close file
Ftp_CloseFile ( var );
// Close connection
Ftp_Close ( );
}
If something still not clear, feel free to ask here
Callbacks
Code:
forward OnFtpFileSent ( remotefile [ ], localfile [ ] );
forward OnFtpFileReceived ( remotefile [ ], localfile [ ] );
Bugs
None yet.
Credits
To RyDeR`, for tutorial.
To Pghpunkid, fo callback tutorial.
To 'Search', for finding all necessary info.
To me, for making a plugin

.
If you have any suggestions, I'll try to make another version, and add them.
Download
Re: FTP -
Gamer_Z - 05.08.2011
I don't think this is cross compatible?
Code:
#include "windows.h"
you should look for an better solution, additionally if u used threads to get the dir list it would be faster?
(and file download etc)
You can find cross compatible FTP library's for C++ very easily, CUrl has also FTP support.
Re: FTP -
wups - 05.08.2011
Nice work!
Ftp_FileExists(remote_file[]) would be nice.
Re: FTP -
rbN. - 05.08.2011
sexy if works :P
Re: FTP -
Gamer_Z - 05.08.2011
Quote:
Originally Posted by wups
Nice work!
Ftp_FileExists(remote_file[]) would be nice.
|
I would suggesting makinf FTP_FileSize, -1 size if file not exist.. so you don't have useless functions.
(btw, size in bytes..)
Re: FTP -
TheArcher - 05.08.2011
Yes nice idea.
Re: FTP -
Scottas - 05.08.2011
Quote:
Originally Posted by Gamer_Z
I don't think this is cross compatible?
Code:
#include "windows.h"
you should look for an better solution, additionally if u used threads to get the dir list it would be faster?
(and file download etc)
You can find cross compatible FTP library's for C++ very easily, CUrl has also FTP support.
|
There is not much I can do, I just started to make plugin ( this is my first try ). Maybe I'll try to use threads, when I gain more experience on programing in C++. And this is the only FTP library I found, if you have any info, you can share it with me

.
By the way, plugin updated.
Re: FTP -
FireCat - 05.08.2011
FINALLY someone created this!
Thank you!
Re: FTP -
Raimis_R - 05.08.2011
Very good Scootland !
Re: FTP -
Patrik356b - 05.08.2011
1. Does this support SSH Transfer ? (I know SSH is different from FTP, but..)
2. Does this support FTPS, FTPES ?
Re: FTP -
Markx - 05.08.2011
Awesome, this can be used as a saving system!
Re: FTP -
QuaTTrO - 05.08.2011
This is awesome ! Good job
Re: FTP - Guest3598475934857938411 - 05.08.2011
Nice plugin mate, keep up the good work. 10/10, shame it is not working with linux :/
Re: FTP -
Scottas - 05.08.2011
Quote:
Originally Posted by Patrik356b
1. Does this support SSH Transfer ? (I know SSH is different from FTP, but..)
2. Does this support FTPS, FTPES ?
|
I don't know, haven't tried them.
Re: FTP -
Gamer_Z - 05.08.2011
well the Curl lubrary has ALOT of support for very different protocols, and if you are a beginner well, I didn't manage the 'how to make threads' stuff... (I'm a novice too if it gets to Cpp)
Re: FTP -
Scottas - 05.08.2011
And Curl library is cross-compatible? I'll take a look at this. But I don't have any idea how to compile plugin on linux
Re: FTP -
Gamer_Z - 06.08.2011
Quote:
Originally Posted by Scottas
And Curl library is cross-compatible? I'll take a look at this. But I don't have any idea how to compile plugin on linux 
|
if you want to compile it on linux u can install (dual boot) a linux on you machine (MUST BE A 32 bit operating system linux!) or you just install vmware workstation and install in there a linux machine and just setup networking, in the sscanf threat u can see a 'makefile', u put that makefile in ur project thing, edit it (eg change all SSCANF instances to FTP) then type "make FTP" (u need to be in the directory of the makefile and the project, eg "cd /Desktop/MyProjects/FTP/" (linux is case sensetive to EVERITHING!)).
BTW I noticed i just said type type.. I am talking about the Terminal.
Re: FTP -
Scottas - 06.08.2011
Thanks for the information.
Re: FTP -
Jay_ - 06.08.2011
PAWN is single threaded. The server will halt until all FTP transfers have taken place. I wouldn't recommend using this. This type of function would be better done using PHP and wrapping it with the HTTP function.
Re: FTP -
Scottas - 06.08.2011
So, this plugin is useless