Hi,
I got an elementary part of WinSCP to work with Delphi XE.
To call WinSCP, I use the function
ShellExecute_AndWait
, which can be found at Torry or here:
https://www.swissdelphicenter.ch/en/showcode.php?id=93
Password, host name and session information is stored in WinSCP.ini - before using Delphi, I established a connection via the WinSCP GUI and saved the session, including the password.
In Delphi, create a form with a button and a memo.
procedure TForm1.Button1Click(Sender: TObject);
var logdir, progdir, paramstring: string;
begin
logdir := 'C:\Users\user\Documents';
progdir := 'C:\Program Files (x86)\WinSCP\WinSCP.exe'; //for use with Win7/x64
paramstring := '/ini=WinSCP.ini /log=logfile.txt /script=C:\Users\user\Documents\upload2.txt';
if ShellExecute_AndWait('open', PChar(progdir), paramstring, logdir, SW_SHOWNORMAL, true) >=0 then
begin
Sleep(1000);
Memo1.Lines.LoadFromFile(logdir + '\logfile.txt');
end
else
ShowMessage('Error 1');
end;
The script file upload2.txt consists of:
option batch abort
option confirm off
open username@hostname.com
put D:\heuteneu.txt /httpdocs/content/test/heuteneu.txt
exit
Maybe someone can help me to solve the next tasks:
- List the content of the remote directory to a stringlist (so it becomes possible to prevent overwriting of existing files)
- get an online error message (not only in the logfile)