Post a reply

Options
Add an Attachment

If you do not want to add an Attachment to your Post, please leave the Fields blank.

(maximum 10 MB; please compress large files; only common media, archive, text and programming file formats are allowed)

Options

Topic review

martin

Re: WinSCP won't run when source file has multiple lines

I do not think this is WinSCP question. It is most likely because you do not trim new lines from the $line.
$line = rtrim($line);
ask.q.9999

WinSCP won't run when source file has multiple lines

I have a PHP script to check if a file exist. I am using a source file that contains the files to check. I am using a foreach loop to read the source file line by line and check if that line/file exist from WinSCP/remote host. The code does not work when the source file has more than one line. I tried to have the source file have only 1 line and it ran fine. Maybe I am missing a config or a line?
foreach(file("$sourcefile") as $line) {
   $path="C:\Program Files (x86)\WinSCP";
   chdir($path);
       
   system("winscp.com /parameter $line /log=C:\Users\USER1\test\log_yesterday.log /ini=nul /script=C:\Users\USER1\test\connect.txt", $excode);
 
   if ($excode == "0") {
      echo "\nFile exist.";
   } else {
      echo "File does not exist";
   }
}