 |
Cheat Engine The Official Site of Cheat Engine
|
| View previous topic :: View next topic |
| Author |
Message |
DeletedUser14087 I post too much
Reputation: 2
Joined: 21 Jun 2006 Posts: 3069
|
Posted: Sun Oct 12, 2008 6:53 am Post subject: [Delphi]Upload A File To A Remote Server W/ ftpPutFile(21) |
|
|
I made a very basic function in Delphi (which can be easily done in C) which lets you upload a file to a remote server using:
*InternetOpen (According to MSDN, this must be used first in order to have an HTTP/S / FTP Session open)
*InternetConnect (Connecting to the server from the client)
*ftpSetCurrentDirectory[Optional] (I used it to change the directory inside the remote server to make it more tidy)
*WaitForSingleObject[Optional] (I used it for the sake of the safeness)
*ftpPutFile (This is the API which uploads the local file to the remote server (remote file))
You may edit it, do what ever you want, just a very basic example
| Code: | function upload_file(remote_server, //by Rot1
directory,
local_file,
remote_file,
user,
pass: PAnsiChar): boolean;
var hInet, hConnect: HINTERNET;
Dir, Put: Boolean;
begin
hInet := InternetOpen(nil, INTERNET_OPEN_TYPE_DIRECT, nil, nil, 0);
hConnect := InternetConnect(hInet,
remote_server,
INTERNET_DEFAULT_FTP_PORT,
user, pass,
INTERNET_SERVICE_FTP,
INTERNET_FLAG_PASSIVE,
0);
Dir := ftpSetCurrentDirectory(hConnect, directory);
WaitForSingleObject(Cardinal(Dir), infinite);
Put := ftpPutFile(hConnect, local_file, remote_file, FTP_TRANSFER_TYPE_BINARY, 0);
InternetCloseHandle(hInet);
InternetCloseHandle(hConnect);
Result:= Put;
end; |
|
|
| Back to top |
|
 |
Stylo Grandmaster Cheater Supreme
Reputation: 3
Joined: 16 May 2007 Posts: 1073 Location: Israel
|
Posted: Sun Oct 12, 2008 1:55 pm Post subject: |
|
|
i tried to convert it to C++, but it keep returning false
anyways here's what i did
| Code: |
BOOL upload_file(wchar_t *szRemoteServer, wchar_t *szDirectory, wchar_t *szLocalFile, wchar_t *szRemoteFile, wchar_t *szUserName, wchar_t *szPassword)
{
HINTERNET hInet, hConnect;
BOOL bDir, bPut;
hInet = InternetOpen(NULL,INTERNET_OPEN_TYPE_DIRECT,NULL,NULL,0);
hConnect = InternetConnect(hInet,szRemoteServer,INTERNET_DEFAULT_FTP_PORT,szUserName,szPassword,INTERNET_SERVICE_FTP,INTERNET_FLAG_PASSIVE,0);
bDir = FtpSetCurrentDirectory(hConnect,szDirectory);
WaitForSingleObject((HANDLE)bDir, INFINITE);
bPut = FtpPutFile(hConnect, szLocalFile, szRemoteFile, FTP_TRANSFER_TYPE_BINARY, 0);
InternetCloseHandle(hInet);
InternetCloseHandle(hConnect);
return bPut;
}
|
_________________
Stylo |
|
| Back to top |
|
 |
DeletedUser14087 I post too much
Reputation: 2
Joined: 21 Jun 2006 Posts: 3069
|
Posted: Sun Oct 12, 2008 2:50 pm Post subject: |
|
|
1qaz, Mine works! you need to put the FULL path for the local file.
| Code: | BOOL Upload_File(LPCSTR lpszServerName, LPCSTR lpszDirectory, LPCSTR lpszUserName, LPCSTR lpszPassword, LPCSTR lpszLocalFile, LPCSTR lpszNewRemoteFile)
{
HINTERNET hInet, hConnect;
BOOL bPut;
hInet = InternetOpenA(NULL, INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
hConnect = InternetConnectA(hInet, lpszServerName, INTERNET_DEFAULT_FTP_PORT, lpszUserName, lpszPassword, INTERNET_SERVICE_FTP, INTERNET_FLAG_PASSIVE, 0);
FtpSetCurrentDirectoryA(hConnect, lpszDirectory);
bPut = FtpPutFileA(hConnect, lpszLocalFile, lpszNewRemoteFile, FTP_TRANSFER_TYPE_BINARY, 0);
InternetCloseHandle(hInet);
InternetCloseHandle(hConnect);
return bPut;
} |
Example: C:\\BlaBla\\lol.txt
Last edited by DeletedUser14087 on Sun Oct 12, 2008 2:57 pm; edited 1 time in total |
|
| Back to top |
|
 |
Stylo Grandmaster Cheater Supreme
Reputation: 3
Joined: 16 May 2007 Posts: 1073 Location: Israel
|
Posted: Sun Oct 12, 2008 2:56 pm Post subject: |
|
|
with what values do you call the procedure?
my values are:
| Code: |
szRemoteServer = 10.0.0.1 // my ip on local network
szDirectory = C:\Program Files
szLocalFile = lol.txt
szRemoteFile = lol.txt
szUserName = 0
szPassword = 0;
|
for some reason i think the problem is in the user / pass parameters
i don't think i should call it with null values
_________________
Stylo |
|
| Back to top |
|
 |
DeletedUser14087 I post too much
Reputation: 2
Joined: 21 Jun 2006 Posts: 3069
|
Posted: Sun Oct 12, 2008 2:59 pm Post subject: |
|
|
| 1qaz wrote: | with what values do you call the procedure?
my values are:
| Code: |
szRemoteServer = 10.0.0.1 // my ip on local network
szDirectory = C:\Program Files
szLocalFile = lol.txt
szRemoteFile = lol.txt
szUserName = 0
szPassword = 0;
|
for some reason i think the problem is in the user / pass parameters
i don't think i should call it with null values |
Woah!! you can't upload the file to YOUR pc, must be a remote FTP server (or HTTP, read about InternetOpen/Connect @ MSDN).
Edit: If you need further help, tell me.
|
|
| Back to top |
|
 |
Stylo Grandmaster Cheater Supreme
Reputation: 3
Joined: 16 May 2007 Posts: 1073 Location: Israel
|
Posted: Sun Oct 12, 2008 3:00 pm Post subject: |
|
|
oh.... so i guess i could upload it to other computer on my local network?
_________________
Stylo |
|
| Back to top |
|
 |
DeletedUser14087 I post too much
Reputation: 2
Joined: 21 Jun 2006 Posts: 3069
|
Posted: Sun Oct 12, 2008 3:02 pm Post subject: |
|
|
| 1qaz wrote: | | oh.... so i guess i could upload it to other computer on my local network? |
I haven't tried, but be my guess, also did you read my last reply ?
The reason it works on the Delphi cause i used GetCurrentDir() which is just a VCL Wrapper which extracts the current folder path the PE is at,
so GetCurrentDir+'\lol.txt' = Full path, not sure how could it be done in C/++.
I optimized the code:
| Code: | BOOL Upload_File(LPCSTR lpszServerName, LPCSTR lpszDirectory, LPCSTR lpszUserName, LPCSTR lpszPassword, LPCSTR lpszLocalFile, LPCSTR lpszNewRemoteFile)
{
HINTERNET hInet, hConnect;
BOOL bPut;
hInet = InternetOpenA(NULL, INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
hConnect = InternetConnectA(hInet, lpszServerName, INTERNET_DEFAULT_FTP_PORT, lpszUserName, lpszPassword, INTERNET_SERVICE_FTP, INTERNET_FLAG_PASSIVE, 0);
if(hConnect != NULL)
__try
{
FtpSetCurrentDirectoryA(hConnect, lpszDirectory);
bPut = FtpPutFileA(hConnect, lpszLocalFile, lpszNewRemoteFile, FTP_TRANSFER_TYPE_BINARY, 0);
}
__finally
{
InternetCloseHandle(hInet);
InternetCloseHandle(hConnect);
}
return bPut;
} |
|
|
| Back to top |
|
 |
Stylo Grandmaster Cheater Supreme
Reputation: 3
Joined: 16 May 2007 Posts: 1073 Location: Israel
|
Posted: Sun Oct 12, 2008 3:14 pm Post subject: |
|
|
InternetConnectA keeps failing me
i guess that's the reason it returns false all the time
also i guess that it doesn't work with local network's computers
to what ftp server did u upload the file
_________________
Stylo |
|
| Back to top |
|
 |
DeletedUser14087 I post too much
Reputation: 2
Joined: 21 Jun 2006 Posts: 3069
|
Posted: Sun Oct 12, 2008 3:23 pm Post subject: |
|
|
| 1qaz wrote: | InternetConnectA keeps failing me
i guess that's the reason it returns false all the time
also i guess that it doesn't work with local network's computers
to what ftp server did u upload the file |
lol any FTP server, doesn't matter.
if you wanna check how it works, make one @ freehostia.com
Edit: Use GetCurrentDirectory() instead of giving the full path of the file (if you wanna upload a specific file from the same folder).
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
|
|