采用Apache服务器,利用http协议格式来访问另一台电脑的文件夹

windows下


1、下载最新的Apache,并对它进行安装和配置。apache安装和配置 (注:apache/conf/httpd.conf里的listen 80这个端口就是访问时加在ip后所要输入的端口,可任意修改)

2、修改和添加Apache的默认站点目录。 修改添加默认站点目录 (暂时只会修改,添加站点功能我失败了)


mac/linux下

        mac自带apache,所以只要你启动apache以后,apache就可以用了。

        但是,当我换了站点目录(修改站点目录和windows类似)以后,我本机访问http://localhost的时候,就提示了Forbidden 403, You don't have permission to access / on this server 这个错误。这时候我就百度必应疯狂搜索,搜到了一篇描述并解决我遇到的类似问题的文章,解决mac Forbidden 403 权限问题

        本来以为,跟着这篇文章整理完以后,应该是可以成功的,可是没有预料到,结果还是失败了。很是苦恼...

        最终各种询问,在我同学的帮助下解决了,如下:

    (问题原因:在解决mac Forbidden 403权限问题 里提到了往/etc/apache2/users下添加{username}.conf,这个是正确的思路。但是apache里,引入/etc/apache2/users文件夹下的文件的语句被注释了,所以即使加了{username}.conf这个文件,apache也不会用到,那么我遇到的那个问题自然无法解决。下面两个步骤就是让apache引入/etc/apache2/users下的文件)

   第一步

       /etc/apache2/httpd.conf   去掉前面的# 如下的行
       # LoadModule php5_module libexec/apache2/libphp5.so
       #LoadModule userdir_module libexec/apache2/mod_userdir.so
       #Include /private/etc/apache2/extra/httpd-userdir.conf
       #LoadModule authz_core_module libexec/apache2/mod_authz_core.so
       #LoadModule authz_host_module libexec/apache2/mod_authz_host.so

   第二步
       /etc/apache2/extra/httpd-userdir.conf  去掉前面的#如下的行
       #Include /private/etc/apache2/users/*.conf


   这样做了以后,问题就完美解决了。

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
您可以使用Java中的FTP客户端库来从另一台服务器上下载文件夹。您需要使用FTP协议连接到远程服务器,然后使用FTP客户端库中的方法下载文件夹。以下是一个简单的Java代码示例,可以从远程服务器下载文件夹: ``` import org.apache.commons.net.ftp.FTP; import org.apache.commons.net.ftp.FTPClient; import java.io.IOException; public class FTPDownloadFolderExample { public static void main(String[] args) { String server = "remote.server.com"; int port = 21; String user = "username"; String pass = "password"; String remoteFolderPath = "/path/to/remote/folder"; String localFolderPath = "/path/to/local/folder"; FTPClient ftpClient = new FTPClient(); try { ftpClient.connect(server, port); ftpClient.login(user, pass); ftpClient.enterLocalPassiveMode(); ftpClient.setFileType(FTP.BINARY_FILE_TYPE); downloadFolder(ftpClient, remoteFolderPath, localFolderPath); ftpClient.logout(); ftpClient.disconnect(); } catch (IOException ex) { ex.printStackTrace(); } } private static void downloadFolder(FTPClient ftpClient, String remoteFolderPath, String localFolderPath) throws IOException { ftpClient.changeWorkingDirectory(remoteFolderPath); String[] subDirectories = ftpClient.listNames(); for (String subDirectory : subDirectories) { if (subDirectory.equals(".") || subDirectory.equals("..")) { continue; } String remoteSubDirectoryPath = remoteFolderPath + "/" + subDirectory; String localSubDirectoryPath = localFolderPath + "/" + subDirectory; downloadFolder(ftpClient, remoteSubDirectoryPath, localSubDirectoryPath); } String[] files = ftpClient.listFiles(); for (String file : files) { String remoteFilePath = remoteFolderPath + "/" + file; String localFilePath = localFolderPath + "/" + file; ftpClient.retrieveFile(remoteFilePath, new FileOutputStream(localFilePath)); } } } ``` 在这个示例中,我们使用了Apache Commons Net库中的FTP客户端来连接到远程服务器,并使用递归函数下载了整个文件夹。请注意,您需要将`server`,`port`,`user`,`pass`,`remoteFolderPath`和`localFolderPath`替换为实际的值。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值