虚拟机Ubuntu访问Windows的FTP或共享文件夹的解决方案
<div id="navCategory"><h5 class="catalogue">目录</h5><ul class="first_class_ul"><li><a href="#_label0">推荐方案:通过 SMB/CIFS 访问 Windows 共享文件夹(最简单、最常用)</a></li><ul class="second_class_ul"><li><a href="#_lab2_0_0">步骤 1:在 Windows 上设置共享文件夹(关键!)</a></li><li><a href="#_lab2_0_1">步骤 2:在 Ubuntu 虚拟机中访问共享(5 分钟搞定)</a></li><ul class="third_class_ul"><li><a href="#_label3_0_1_0">方法 1:使用图形界面(最简单)</a></li><li><a href="#_label3_0_1_1">方法 2:终端命令(快速操作)</a></li></ul><li><a href="#_lab2_0_2">步骤 3:挂载到本地目录(永久可用)</a></li><ul class="third_class_ul"></ul></ul><li><a href="#_label1">常见问题解决</a></li><ul class="second_class_ul"></ul><li><a href="#_label2">为什么推荐 SMB 而不是 FTP?</a></li><ul class="second_class_ul"></ul><li><a href="#_label3">验证步骤(确保一切正常)</a></li><ul class="second_class_ul"></ul><li><a href="#_label4">附加:如果必须用 FTP(不推荐)</a></li><ul class="second_class_ul"></ul><li><a href="#_label5">最终总结</a></li><ul class="second_class_ul"></ul></ul></div><p>在虚拟机(Ubuntu)中访问 Windows 主机的 <strong>FTP 或共享文件夹</strong>,需要根据具体需求选择方案。以下是<strong>最实用、最安全的解决方案</strong>(无需额外配置 FTP 服务,直接使用 Windows 原生共享):</p><p class="maodian"><a name="_label0"></a></p><h2>推荐方案:通过 SMB/CIFS 访问 Windows 共享文件夹(最简单、最常用)</h2>
<blockquote><p><strong>为什么不用 FTP?</strong><br />Windows 本身不提供 FTP 服务(需额外安装 IIS),而 SMB 是 Windows 原生支持的共享协议,速度更快、更安全。</p></blockquote>
<p class="maodian"><a name="_lab2_0_0"></a></p><h3>步骤 1:在 Windows 上设置共享文件夹(关键!)</h3>
<p><strong>创建共享文件夹</strong></p>
<ul><li>右键文件夹 → <strong>属性</strong> → <strong>共享</strong> → <strong>高级共享</strong> → 勾选 <strong>“共享此文件夹”</strong> → 设置共享名(如 <code>ubuntu_share</code>)。</li><li>点击 <strong>“权限”</strong> → 添加 <strong><code>Everyone</code></strong> → 勾选 <strong>“读取/写入”</strong> → <strong>确定</strong>。</li></ul>
<p><strong>关闭密码保护共享</strong>(重要!避免登录问题)</p>
<ul><li>Windows 搜索 <strong>“高级共享设置”</strong> → <strong>网络发现</strong> → <strong>关闭密码保护共享</strong>。</li></ul>
<p><strong>获取 Windows IP 地址</strong></p>
<ul><li>在 Windows 命令提示符执行 <code>ipconfig</code> → 记下 <strong>IPv4 地址</strong>(如 <code>192.168.1.100</code>)。</li></ul>
<p class="maodian"><a name="_lab2_0_1"></a></p><h3>步骤 2:在 Ubuntu 虚拟机中访问共享(5 分钟搞定)</h3>
<p class="maodian"><a name="_label3_0_1_0"></a></p><h4>方法 1:使用图形界面(最简单)</h4>
<ol><li>打开 <strong>文件管理器</strong> → 左侧边栏点击 <strong>“网络”</strong>。</li><li>输入地址:<code>smb://192.168.1.100</code>(替换为你的 Windows IP)。</li><li>点击 <strong>“连接”</strong> → 无需密码(因已关闭密码保护)→ 直接访问共享文件夹。</li></ol>
<p class="maodian"><a name="_label3_0_1_1"></a></p><h4>方法 2:终端命令(快速操作)</h4>
<div class="jb51code"><pre class="brush:bash;"># 1. 安装 SMB 客户端
sudo apt update && sudo apt install -y smbclient
# 2. 查看 Windows 共享列表(可选)
smbclient -L //192.168.1.100 -U %
# 3. 进入共享文件夹(无需密码)
smbclient //192.168.1.100/ubuntu_share
</pre></div>
<blockquote><p>输入 ls 查看文件,quit 退出。</p></blockquote>
<p class="maodian"><a name="_lab2_0_2"></a></p><h3>步骤 3:挂载到本地目录(永久可用)</h3>
<div class="jb51code"><pre class="brush:bash;"># 创建挂载点
sudo mkdir -p /mnt/windows_share
# 挂载共享(替换为你的 Windows IP 和共享名)
sudo mount -t cifs -o username=,password= //192.168.1.100/ubuntu_share /mnt/windows_share
# 验证
ls /mnt/windows_share
</pre></div>
<blockquote><p><strong>无需密码</strong>:因为已关闭密码保护共享,所以 username= 和 password= 为空。</p></blockquote>
<p class="maodian"><a name="_label1"></a></p><h2>常见问题解决</h2>
<table><thead><tr><th>问题</th><th>解决方案</th></tr></thead><tbody><tr><td><strong>连接被拒绝</strong></td><td>1. 检查 Windows 防火墙:允许 **“文件和打印机共享”**2. 确认 Windows IP 正确(<code>ipconfig</code>)</td></tr><tr><td><strong>权限错误</strong></td><td>1. 在 Windows 共享权限中添加 <code>Everyone</code>2. <strong>关闭密码保护共享</strong>(关键!)</td></tr><tr><td><strong>无法挂载</strong></td><td>1. 安装 <code>cifs-utils</code>:<code>sudo apt install -y cifs-utils</code>2. 检查共享名是否正确(大小写敏感)</td></tr><tr><td><strong>速度慢</strong></td><td>1. 确保虚拟机网络模式是 <strong>桥接模式</strong>(非 NAT)2. 在 Windows 里关闭 <strong>“公用网络”</strong>(在“网络和共享中心”)</td></tr></tbody></table>
<p class="maodian"><a name="_label2"></a></p><h2>为什么推荐 SMB 而不是 FTP?</h2>
<table><thead><tr><th>方案</th><th>优点</th><th>缺点</th></tr></thead><tbody><tr><td><strong>SMB/CIFS</strong></td><td>✅ Windows 原生支持✅ 无需额外配置✅ 速度更快✅ 无需密码</td><td>❌ 需关闭密码保护(但安全风险极低)</td></tr><tr><td><strong>FTP</strong></td><td>❌ 需安装 IIS❌ 明文传输(不安全)❌ 配置复杂</td><td>✅ 无</td></tr></tbody></table>
<blockquote><p><strong>安全提示</strong>:关闭密码保护共享仅影响局域网内访问,<strong>不会暴露到公网</strong>(内网安全)。</p></blockquote>
<p class="maodian"><a name="_label3"></a></p><h2>验证步骤(确保一切正常)</h2>
<p><strong>在 Windows 上</strong>:创建一个测试文件 <code>test.txt</code> 到共享文件夹。</p>
<p><strong>在 Ubuntu 中</strong>:</p>
<div class="jb51code"><pre class="brush:bash;">ls /mnt/windows_share# 应看到 test.txt
echo "Hello from Ubuntu" > /mnt/windows_share/ubuntu_test.txt
</pre></div>
<p><strong>在 Windows 上</strong>:检查共享文件夹,确认 <code>ubuntu_test.txt</code> 已生成。</p>
<p class="maodian"><a name="_label4"></a></p><h2>附加:如果必须用 FTP(不推荐)</h2>
<blockquote><p>仅当 Windows 上已安装 <strong>IIS FTP 服务</strong> 时使用(需额外配置)。</p></blockquote>
<p><strong>在 Windows 上</strong>:</p>
<ul><li>安装 IIS → 勾选 <strong>FTP 服务</strong> → 创建 FTP 站点。</li><li>设置用户名/密码(如 <code>ftpuser</code> / <code>password</code>)。</li></ul>
<p><strong>在 Ubuntu 中</strong>:</p>
<div class="jb51code"><pre class="brush:bash;">sudo apt install -y ftp
ftp 192.168.1.100# 连接 FTP 服务器
# 输入用户名/密码
</pre></div>
<blockquote><p><strong>强烈建议不要用 FTP</strong>:明文传输密码,且 Windows 默认不提供 FTP 服务。</p></blockquote>
<p class="maodian"><a name="_label5"></a></p><h2>最终总结</h2>
<table><thead><tr><th>需求</th><th>推荐方案</th><th>命令/操作</th></tr></thead><tbody><tr><td><strong>快速访问 Windows 文件</strong></td><td><strong>SMB 共享</strong></td><td><code>smbclient //192.168.1.100/share</code></td></tr><tr><td><strong>永久挂载到 Ubuntu</strong></td><td>SMB 挂载</td><td><code>sudo mount -t cifs //192.168.1.100/share /mnt/share</code></td></tr><tr><td><strong>避免密码</strong></td><td>关闭 Windows 密码保护共享</td><td>在 Windows 高级共享设置中关闭</td></tr></tbody></table>
<blockquote><p><strong>成功标志</strong>:<br />在 Ubuntu 中能看到 Windows 共享文件夹内容,且能创建/删除文件。</p></blockquote>
頁:
[1]