[英]PHP CLI - FTP Multiple Files
完成新手學習,仍在學習。
我在Windows 7上安裝了PHP 7.2,並將其用作CLI來移動文件。
我可以將文件上傳到多個FTP服務器。 我現在希望能夠上傳文件夾中的所有文件。
我一次只能做一個,但這似乎並不是最有效的方法。
這是我的單個文件上傳腳本的示例片段:
<?php
$ostream = fopen("ssh2.sftp://$sftp" . $remoteFile_Official, 'w');
$ofile = file_get_contents($localFile_Official);
fwrite($ostream, $ofile);
fclose($ostream);
?>
謝謝你提前。
嘗試這個 。
<?php
$dir = "/images/";
// Open a directory, and read its contents
if (is_dir($dir)){
if ($dh = opendir($dir)){
while (($file = readdir($dh)) !== false){
$ostream = fopen("ssh2.sftp://$sftp" . $file, 'w');
$ofile = file_get_contents($localFile_Official);
fwrite($ostream, $ofile);
fclose($ostream);
}
closedir($dh);
}
}
?>
這是完整的代碼
// set up basic ssl ftp connection
$conn_id = ssh2_connect($ftp_server, 22);
ssh2_auth_password($conn_id, $ftp_username, $ftp_userpass);
// Open SSL session
$sftp = ssh2_sftp($conn_id);
$Official = "/FTP/LPS Data/ATC/RHIL/20190119_RHIL/XML";
$dir = "Z:\adminshare\Rosehill\190119_Rosehill Gardens\XML\Race_4\\";
// Open a directory, and read its contents
if (is_dir($dir)){
if ($dh = opendir($dir)){
while (($file = readdir($dh)) !== false){
$stream = fopen("ssh2.sftp://$sftp" . $file, 'w');
$file = file_get_contents($remoteFile_Official);
fwrite($stream, $file);
fclose($stream);
}
closedir($dh);
}
}
希望能有所幫助
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.