2016-02-06 26 views
1

我在Windows中設置了我的IIS服務器並設置了應該只能下載的文件夾列表。現在我使用PHP連接到服務器了。如何使用php下載列出iis的ftp服務器的所有目錄

$username=$_POST["username"]; 
$password=$_POST["paswd"]; 
$host="localhost"; 
$ftpcon= ftp_connect($host) or die("could not connect"); 
$login=ftp_login($ftpcon,$username,$password); 

現在我想列出的是windows目錄。這將幫助我在Windows中瀏覽文件資源管理器。你介意給我一些幫助這裏

回答

0

嘗試下面的代碼列出所有文件&目錄:

<?php 
$ftp_server = 'xxx.xx.xx.xx';//Replace with your IP 
$conn_id = ftp_connect($ftp_server); 

# login with username and password 
$user = 'ftp_user_name'; //Replace with your FTP User name 
$passwd = 'ftp_password'; //Replace with your FTP Password 
$login_result = ftp_login($conn_id, $user, $passwd); 

# check connection 
if (!$conn_id) 
{ 
    echo "FTP connection has failed!"; 
    echo "Attempted to connect to $ftp_server for user $user"; 
    exit(); 
} 
else 
{ 
    $cwd   = ftp_pwd($conn_id); 
    $contentList = ftp_nlist($conn_id, "."); // This denotes the current path, you can replace this with your actual path 

    foreach($contentList as $contentListItem) 
    { 
     if (ftp_size($conn_id, $contentListItem) == -1) 
     { 
      #Its a direcotry 
      echo "Directory : ".$contentListItem."<br>"; 
     } 
     else 
     { 
      #Its a file 
      echo "File : ".$contentListItem."<br>"; 
     } 
    } 
} 
?> 

+0

你的代碼產生3錯誤。 –

+0

警告:ftp_login():結束於第8行的C:\ xampp \ htdocs \ mainproject \ testingconnection.php 警告:ftp_pwd():請用USER和PASS登錄。第19行中的C:\ xampp \ htdocs \ mainproject \ testingconnection.php 警告:爲第22行的C:\ xampp \ htdocs \ mainproject \ testingconnection.php中的foreach()提供的無效參數 –

相關問題