[Plugin] FTP
#1

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
Reply
#2

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.
Reply
#3

Nice work!
Ftp_FileExists(remote_file[]) would be nice.
Reply
#4

sexy if works :P
Reply
#5

Quote:
Originally Posted by wups
View Post
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..)
Reply
#6

Yes nice idea.
Reply
#7

Quote:
Originally Posted by Gamer_Z
View Post
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.
Reply
#8

FINALLY someone created this!
Thank you!
Reply
#9

Very good Scootland !
Reply
#10

1. Does this support SSH Transfer ? (I know SSH is different from FTP, but..)
2. Does this support FTPS, FTPES ?
Reply
#11

Awesome, this can be used as a saving system!
Reply
#12

This is awesome ! Good job
Reply
#13

Nice plugin mate, keep up the good work. 10/10, shame it is not working with linux :/
Reply
#14

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.
Reply
#15

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)
Reply
#16

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
Reply
#17

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.
Reply
#18

Thanks for the information.
Reply
#19

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.
Reply
#20

So, this plugin is useless
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)