WinSCP won't run when source file has multiple lines

Advertisement

ask.q.9999
Joined:
Posts:
1
Location:
Manila

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";
   }
}

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
41,518
Location:
Prague, Czechia

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);

Reply with quote

Advertisement

You can post new topics in this forum