1

I am using the code below to get all files from a folder via curl sftp.

$ch = curl_init('sftp://' . $sftpServer . ':' . $sftpPort . $sftpRemoteDir . '/');
        
curl_setopt($ch, CURLOPT_USERPWD, '*******:*******');
curl_setopt($ch, CURLOPT_PROTOCOLS, CURLPROTO_SFTP);
curl_setopt($ch, CURLOPT_DIRLISTONLY, '1L');
$response = curl_exec($ch);

I have tried explode() and preg_match() but for some reason I can't parse the list of results:

641265471.txt_20220103_220501
641269117.txt_20220103_230501
..

How can I actually parse the data above to each new line being an array item ?

5
  • 1
    Does $array = explode("\n", $response) work? Commented Jan 4, 2022 at 22:10
  • unfortunately no Commented Jan 4, 2022 at 22:14
  • preg_split('~\R~', $response) maybe ? Commented Jan 4, 2022 at 22:20
  • It seems curl_exec($ch); is automatically echo'ing the results and "$response" is = 1 Commented Jan 4, 2022 at 22:24
  • 1
    @ClintC. Oh right, forgot the basics ! Glad to know it works the same for HTTP and SFTP. Commented Jan 4, 2022 at 22:27

1 Answer 1

1

I completely forgot to add

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

which is needed to capture the response.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.