Jenkins使用FTP上传文件报错问题处理

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接: https://blog.csdn.net/smooth00/article/details/88734958

Jenkins带有Publish over FTP插件,安装后并使用它就能实现FTP上传,可以用于构建后的发包操作。我们在系统管理中配置好FTP Servers后,并测试连接通过,按理在Job配置中用Publish over FTP按官网的配置说明进行配置(Publish Over FTP Plugin),构建后就能正常上传文件。可是我们可能会遇到以后问题:

问题一:不支持中文目录

报错如下:

关看报错提示一般人打死都想不到是中文目录引起的,如果知道其实解决起来很容易,做如下配置:

【系统管理】->【系统设置】->【Publish over FTP】->高级:【Control encoding】->输入【UTF-8】或者【GB2312】

虽然Jenkins说明中推荐中文配置为GB2312,但其实我们一般通用的作法是设置为UTF-8,兼容各类操作系统和构建环境。

问题二:不支持FTP被动模式(PASV)

报错如下:

 上网查有关FTP报502 Command not implemented错误,可能都会说到要开启FTP被动(PASV)模式,那解决方法就有两种了,一种是在FTP服务端开启PASV被动模式(一般默认两种模式都开启了,但不排除没有开启的情况,就导致这个问题)。我们通过FlashFXP工具去连接FTP服务器,也能看出是否开启了PASV模式:

可以看出FTP客户端默认都是用PASV模式去连接服务端,如果连接失败后会自动转为PORT主动模式,说明我们的Jenkins不会自动去转换连接模式,所以导致了上传文件报502错误。 

所以,另一种方式就是改变Jenkins的连接模式,通过官网也能找到这一段话:

Use active data mode
By default passive mode will be used to connect to the FTP Server.
In passive mode the client initiates all connections which will allow the client to send files through a firewall that has been configured to refuse all inbound connections (and does not create dynamic rules).
If you want to dissable passive mode, and have the client use PORT commands for the server to connect to the client to retieve the files, then you can check this box.

 从这段话可以看出,我们是需要自己设置连接模式的(默认是PASV模式,至于PORT与PASV两种模式的区别,可以上网百度),配置如下:

系统管理】->【系统设置】->【Publish over FTP】->高级:勾选【Use active data mode】

保存设置后,再次构建项目,就能看到FTP上传成功了!

猜你喜欢

转载自blog.csdn.net/smooth00/article/details/88734958