---
title: "Ftpsclient上传文件到ftp时storeFile总是返回false（522 data connections must be encrypted）"
author: "shukuiyan"
date: "2016-07-22T15:25:16Z"
tags: []
categories: ["互联网"]
slug: "ftpsclient-ftp-storefile-false-522-data-connections-must-be-encrypted"
draft: false
lastmod: "2016-07-22T15:25:16Z"
id: 2312901
url: "https://shukuiyan.iteye.com/blog/2312901"
---

使用java中org.apache.commons.net.ftp的FTPSClient将文件上传服务器时，调用storeFile总是返回false。

及时打印fClient.getReplyCode()和fClient.getReplyString()，返回522 data connections must be encrypted。

后来增加如下代码，解决问题

```
this.fClient.enterLocalPassiveMode();
this.fClient.setFileTransferMode(FTP.STREAM_TRANSFER_MODE);
this.fClient.execPROT("P");
```