跳转到内容

Ftp测试任务

Ftp测试任务 定义一个 Ftp 协议测试任务,用于 Ftp 功能、性能、稳定性和自定义测试。

主参数清单

参数类型必填长度限制说明
targetenum-任务类型
固定值:FTP
namestring≤400 字符任务名称
唯一标识 FTP 任务
descriptionstring≤800 字符任务描述
详细说明任务目的
enabledboolean-启用状态
true:启用(默认)
false:禁用
beforeNamestring≤400 字符前序任务
控制任务执行顺序
serverobject-服务器配置
详见下方服务器配置说明
uploadFileboolean-传输方向
true:上传
false:下载(默认)
uploadFileSourceenum-文件来源
REMOTE_FILE:远程文件
REMOTE_URL:远程 URL
LOCAL_FILE:本地文件(默认)
remoteFileNamestring≤4096 字符远程文件名
上传:保存的文件名
下载:下载的文件名
remoteFileUrlstring≤4096 字符远程文件 URL
上传时从此 URL 下载文件
localFileNamestring≤4096 字符本地文件名
上传:本地文件路径
下载:保存的本地路径
localFileContentstring≤2MB本地文件内容
支持 Base64/Gzip 编码
localFileContentEncodingenum-内容编码
none:明文
base64:Base64 编码
gzip_base64:Gzip 压缩后 Base64
binaryModeboolean-传输模式
true:二进制模式
false:文本模式

注意

支持同时编排多个 Ftp 接口,但每次只允许启用一个 Ftp 进行测试。

Ftp完整结构配置示例:

yaml
- target: FTP
  name: UploadFromLocalFile
  description: Upload file from local file
  enabled: true
  server:
    # FTP服务器配置 ...
  uploadFile: true
  uploadFileSource: LOCAL_FILE
  remoteFileName: remote.txt
  localFileName: local.txt
  localFileContent: This is a text file content
  localFileContentEncoding: none
  binaryMode: false

服务器配置 (server)

字段名称类型必填长度/范围限制默认值描述
serverstring≤253 字符-FTP 服务器地址
支持 IP 地址或完整域名
示例:ftp.example.com
portinteger1-6553521服务端口
标准端口:21(命令端口)
数据传输端口根据模式自动分配
usernamestring条件≤400 字符-认证账号
服务器要求认证时必填
示例:ftpuser
passwordstring条件≤4096 字符-认证凭证
采用加密存储和传输
企业级建议使用 SFTP 替代 FTP
readTimeoutstring1s-24h60s数据传输超时
格式:数字+单位(如 30s)
大文件传输建议增大至 300s
connectTimeoutstring1s-24h6s连接建立超时
格式:数字+单位(如 10s)
跨地域连接建议 15-30s

Ftp服务器配置示例:

yaml
server:
  server: localhost
  port: 8084
  username: admin
  password: 123456
  readTimeout: 60s
  connectTimeout: 6s

文件传输方向 (uploadFile)

  • 上传 (true):将文件从本地传输到FTP服务器
  • 下载 (false):从FTP服务器获取文件到本地

文件来源 (uploadFileSource)

来源适用场景关联参数
LOCAL_FILE使用本地文件localFileName
localFileContent
REMOTE_FILE使用FTP服务器文件remoteFileName
REMOTE_URL从URL获取文件remoteFileUrl

传输模式 (binaryMode)

模式适用文件类型特点
二进制模式图片/视频/压缩文件保持文件完整性
文本模式文本文件自动转换换行符

脚本示例(target)

完整参数配置示例

yaml
- target: FTP
  name: UploadFromLocalFile
  description: Upload file from local file
  enabled: true
  server:
    server: localhost
    port: 8084
    username: admin
    password: 123456
    readTimeout: 60s
    connectTimeout: 6s
  uploadFile: true
  uploadFileSource: LOCAL_FILE
  remoteFileName: remote.txt
  localFileName: local.txt
  localFileContent: This is a text file content
  localFileContentEncoding: none
  binaryMode: false

从服务器中下载对应文件用于上传示例

yaml
- target: FTP
  name: UploadFromRemoteFtpFile
  description: Download a file from the Ftp server and then upload it
  server:
    server: localhost
    port: 8084
    username: admin
    password: 123456
  uploadFile: true
  uploadFileSource: REMOTE_FILE
  remoteFileName: remote.txt

根据远程URL资源下载文件用于上传示例

yaml
- target: FTP
  name: UploadFromRemoteUrl
  description: Download a file from the Ftp server and then upload it
  server:
    server: localhost
    port: 8084
    username: admin
    password: 123456
  uploadFile: true
  uploadFileSource: REMOTE_URL
  remoteFileUrl: https://pics6.baidu.com/feed/d50735fae6cd7b897fbfd8ad27e746a9d8330e1a.jpeg

上传本地文件示例

yaml
- target: FTP
  name: UploadFromLocalFile
  description: Upload file from local file
  server:
    server: localhost
    port: 8084
    username: admin
    password: 123456
  uploadFile: true
  uploadFileSource: LOCAL_FILE
  remoteFileName: remote.txt
  localFileName: local.txt
  localFileContent: This is a text file content

上传本地文件Base64编码示例

yaml
- target: FTP
  name: UploadAndEncodingFromLocalFile
  description: Upload and encode file from local file
  server:
    server: localhost
    port: 8084
    username: admin
    password: 123456
  uploadFile: true
  uploadFileSource: LOCAL_FILE
  remoteFileName: remote.txt
  localFileName: local.txt
  localFileContent: VGhpcyBpcyBhIHRleHQgZmlsZSBjb250ZW50
  localFileContentEncoding: base64
  binaryMode: false

下载文件实例

yaml
- target: FTP
  name: RetrieveFile
  description: Retrieve file from remote Ftp server
  server:
    server: localhost
    port: 8084
    username: admin
    password: 123456
  uploadFile: true
  remoteFileName: test.txt

下载并重命名文件示例

yaml
- target: FTP
  name: RetrieveAndRenameFile
  description: "Retrieve file from remote Ftp server and save it. Note: By default,\
    \ it is saved in the execution data directory."
  server:
    server: localhost
    port: 8084
    username: admin
    password: 123456
  uploadFile: true
  remoteFileName: remote.txt
  localFileName: new_file.txt

基于 GPL-3.0 许可发布