Raised This Month: $ Target: $400
 0% 

FTP Upload


Post New Thread Reply   
 
Thread Tools Display Modes
FaTony
Veteran Member
Join Date: Aug 2008
Old 12-14-2010 , 15:12   Re: FTP Upload
Reply With Quote #11

http://stackoverflow.com/questions/1.../c-ftp-library

Download source code, look.
__________________
FaTony is offline
dordnung
Veteran Member
Join Date: Apr 2010
Old 12-14-2010 , 15:23   Re: FTP Upload
Reply With Quote #12

I don't understand much c/c++ ;D

But i founf this:

Code:
Passive Mode FTP works like this: 
    -Client connects to FTP Server on Port 21 (the "control" connection).
    -Clent tells FTP Server it wants to perform transfers in PASV mode and issues    a PASV command to the remote side.
    -Server sends back the port it is listening on as part of the response.
    -Client initiates a command that requires data to the port specified in the    response to the PASV request (e.g. ls, file xfer).
But this is how i do it ?
__________________
dordnung is offline
pheadxdll
AlliedModders Donor
Join Date: Jun 2008
Old 12-14-2010 , 16:22   Re: FTP Upload
Reply With Quote #13

There's no extension that will work, so if you can't create it, you're out of luck.
__________________
pheadxdll is offline
dordnung
Veteran Member
Join Date: Apr 2010
Old 12-14-2010 , 16:45   Re: FTP Upload
Reply With Quote #14

mhh ;D

but i'm nearly finished, only the part with the "STOR" Command missing
__________________
dordnung is offline
FaTony
Veteran Member
Join Date: Aug 2008
Old 12-14-2010 , 17:13   Re: FTP Upload
Reply With Quote #15

Learn C\C++, look at the source code. No other alternatives.
__________________
FaTony is offline
dordnung
Veteran Member
Join Date: Apr 2010
Old 12-15-2010 , 08:00   Re: FTP Upload
Reply With Quote #16

I found a python lib, names ftplib.

There it works somethink like this:

PHP Code:
self.sock socket.socket(afsocktypeproto// Open Socket
self.sock.connect(sa// connect to the socket 
PHP Code:
self.sock.sendall("USER UserName\r\n"
PHP Code:
self.sock.sendall("PASS Password\r\n"
PHP Code:
parse227(self.sendcmd('PASV')) // parse229 converts the PASV return to Host + Port 
PHP Code:
conn socket.socket(afsocktypeproto)
            
conn.connect(sa// Connect to the new PASV Host + Port 
PHP Code:
self.sock.sendall("STOR FileName\r\n"// To the old Socket, not new! 
PHP Code:
conn.sendall("File Content"
Put thats exaclty what i did ?
__________________
dordnung is offline
YamiKaitou
Has a lovely bunch of coconuts
Join Date: Apr 2006
Location: Texas
Old 12-15-2010 , 08:04   Re: FTP Upload
Reply With Quote #17

Maybe looking at this thread will help you understand a bit more. Note that the thread is coded using AMXModX Pawn, so you can't don't a 100% copy and paste of it, but the concept should still be the same.
__________________
ProjectYami Laboratories

I do not browse the forums regularly anymore. If you need me for anything (asking questions or anything else), then PM me (be descriptive in your PM, message containing only a link to a thread will be ignored).
YamiKaitou is offline
dordnung
Veteran Member
Join Date: Apr 2010
Old 12-15-2010 , 13:42   Re: FTP Upload
Reply With Quote #18

Aaaah, thank you very much YamiKaitou, that helps me a lot and it works now

Here is the final code:

PHP Code:
#include <sourcemod>
#include <socket>

#define BUFFER_SIZE 1024

enum SocketTypes
{
    
Handle:SOCKET_CMD,
    
Handle:SOCKET_DATA
}

enum FTPInfo
{
    
Sockets[SocketType],
    
String:Server[40],
    
Port,
    
String:UserName[32],
    
String:Password[32],
    
String:LocalFile[64],
    
String:RemoteFile[64],
    
String:DataServer[16],
    
String:RemoteFilePath[256],
    
DataPort,
    
bool:ReadyForData,
    
bool:StartTransfer,
    
bool:DataConnected,
    
BytesTransferred,
    
Handle:FileHandle,
    
FileSizeUpload
}

new 
FTP[FTPInfo];
new 
String:DataBuffer[BUFFER_SIZE]

public 
FileTransfer(const String:szServer[], const iPort, const String:szUser[], const String:szPassword[], const String:szLocalFile[], const String:szRemoteFile[])
{
    
Format(FTP[Server], sizeof(FTP[Server]), szServer );
    
FTP[Port] = iPort;
    
Format(FTP[UserName], sizeof(FTP[UserName]), "USER %s\r\n"szUser);
    
Format(FTP[Password], sizeof(FTP[Password]), "PASS %s\r\n"szPassword);
    
Format(FTP[LocalFile], sizeof(FTP[LocalFile]), szLocalFile);
    
Format(FTP[RemoteFile], sizeof(FTP[RemoteFile]), szRemoteFile);
    
Format(FTP[RemoteFilePath], sizeof(FTP[RemoteFilePath]), "STOR %s\r\n"szRemoteFile);

    
FTP[FileSizeUpload] = 0;
    
FTP[ReadyForData] = false;
    
FTP[StartTransfer] = false;
    
FTP[DataConnected] = false;

    
FTP[Sockets][SOCKET_CMD] = SocketCreate(SOCKET_TCPOnSocketError);
    
    if (
FTP[Sockets][SOCKET_CMD]) SocketConnect(FTP[Sockets][SOCKET_CMD], OnSocketConnectedOnSocketReceiveOnSocketDisconnectedFTP[Server], FTP[Port])
}

public 
OnSocketError(Handle:socket, const errorType, const errorNumany:arg
{
    
LogError("socket error %d (errno %d)"errorTypeerrorNum);
    
CloseHandle(socket);
}

public 
OnSocketConnected(Handle:socketany:arg
{
    if (
FTP[StartTransfer]) FTP[DataConnected] = true;
}

public 
OnSocketReceive(Handle:socketString:receiveData[], const dataSizeany:arg
{
    
PrintToServer(receiveData);
    if (!
StrContains(receiveData"331"))
    {
        
SocketSend(FTP[Sockets][SOCKET_CMD], FTP[Password]);
    }
    if (!
StrContains(receiveData"220"))
    {
        
SocketSend(FTP[Sockets][SOCKET_CMD], FTP[UserName]);
    }
    else if (!
StrContains(receiveData"230"))
    {
        
SocketSend(FTP[Sockets][SOCKET_CMD], "PASV\r\n");
    }
    else if (!
StrContains(receiveData"200"))
    {
        if (!
FTP[ReadyForData])
        {
            
SocketSend(FTP[Sockets][SOCKET_CMD] , "MODE S\r\n");
            
FTP[ReadyForData] = true;
        }
        else
        {
            
FTP[StartTransfer] = true;
            
FTP[Sockets][SOCKET_DATA] = SocketCreate(SOCKET_TCPOnSocketError);
            
SocketConnect(FTP[Sockets][SOCKET_DATA], OnSocketConnectedOnSocketReceiveOnSocketDisconnectedFTP[DataServer], FTP[DataPort])
            
FTP[FileHandle] = OpenFile(FTP[LocalFile], "rb");
            
FTP[FileSizeUpload] = FileSize(FTP[LocalFile]);

            if (
FTP[Sockets][SOCKET_DATA] != INVALID_HANDLE && FTP[FileHandle] != INVALID_HANDLESocketSend(FTP[Sockets][SOCKET_CMD], FTP[RemoteFilePath]);
        }
    }
    else if (!
StrContains(receiveData"227")) 
    {
        
decl String:buffers[6][10];
        
decl String:CopyReceiver[512];
        
decl String:part[128];
        
        
Format(CopyReceiversizeof(CopyReceiver), receiveData)
        
        
SplitString(CopyReceiver"("partsizeof(part))
        
ReplaceString(CopyReceiversizeof(CopyReceiver), part"")
        
ReplaceString(CopyReceiversizeof(CopyReceiver), ")""")
        
ReplaceString(CopyReceiversizeof(CopyReceiver), "(""")
        
ExplodeString(CopyReceiver","buffers69)
        
Format(FTP[DataServer], sizeof(FTP[DataServer]), "%s.%s.%s.%s"buffers[0], buffers[1], buffers[2], buffers[3]);
        
FTP[DataPort] = (StringToInt(buffers[4]) * 256 ) + StringToInt(buffers[5])
        
        
SocketSend(FTP[Sockets][SOCKET_CMD], "TYPE I\r\n");
    }
}

public 
OnGameFrame()
{
    if (
FTP[DataConnected])
    {
        new 
iBlocksRead;
        
iBlocksRead ReadFileString(FTP[FileHandle], DataBufferBUFFER_SIZE1024);
        
SocketSend(FTP[Sockets][SOCKET_DATA], DataBuffer);        
        
        
FTP[BytesTransferred] += iBlocksRead;
        
        if (
FTP[FileSizeUpload] && (FTP[BytesTransferred] == FTP[FileSizeUpload]))
        {
            
CloseHandle(FTP[FileHandle]);

            
SocketSend(FTP[Sockets][SOCKET_CMD], "QUIT\r\n");

            
CloseHandle(FTP[Sockets][SOCKET_DATA]);
            
CloseHandle(FTP[Sockets][SOCKET_CMD]);
            
            
FTP[StartTransfer] = false;
            
FTP[DataConnected] = false;
        }
    }
}

public 
OnSocketDisconnected(Handle:socketany:arg
{
    
CloseHandle(socket);

__________________
dordnung is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 10:45.


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