上下求索

初探LoadRunner之FTP协议

上一篇 / 下一篇  2009-06-25 15:44:51

曾经采用LR对FTP服务器进行过压力测试,模拟上传和下载等操作业务,LR对FTP的录制好像支持得不是很好,尝试录制cuteFTP以及flashxp都是仅录制到事件,未能生成脚本。

网上搜索了下,找到了这篇文章,基本已涵盖了loadrunner中ftp协议的相关问题,参照以下函数手动编写一个简单的ftp协议脚本即可。

Function Name

Description

ftp_delete

Deletes a file from an FTP server.

ftp_delete_ex

Deletes a file from an FTP server for a specific session.

ftp_dir

Runs the dir command on the FTP server.

ftp_dir_ex

Runs the dir command on the FTP server for a specific session.

ftp_get

Gets a file from an FTP server.

ftp_get_ex

Gets a file from an FTP server for a specific session.

ftp_get_last_download_details

Gets the duration and received byte count of the last ftp_get call.

ftp_get_last_download_details_ex

Gets the duration and received byte count of the last ftp_get call in the session.

ftp_get_last_error

Retrieves the last error received from the FTP server.

ftp_get_last_error_id

Retrieves the ID of the last error that was received from the FTP server.

ftp_get_last_handshake_duration

Returns the duration of the most recent connection creation.

ftp_get_last_handshake_duration_ex

Returns the duration of the most recent connection creation for a specific session.

ftp_get_last_transfer_duration

Returns the net file transfer time.

ftp_get_last_transfer_duration_ex

Returns the net file transfer time for the specific session.

ftp_logon

Performs a logon to an FTP server.

ftp_logon_ex

Performs a logon to an FTP server for a specific session.

ftp_logout

Performs a logout from an FTP server.

ftp_logout_ex

Performs a logout from an FTP server for a specific session.

ftp_mkdir

Creates a directory on the FTP server machine.

ftp_mkdir_ex

Creates a directory on the FTP server machine for a specific session.

ftp_put

Puts a file on an FTP server.

ftp_put_ex

Puts a file on an FTP server for a specific session.

ftp_rendir

Renames a file or directory on the FTP server machine.

ftp_rendir_ex

Renames a file or directory on the FTP server machine for a specific session.

ftp_rmdir

Deletes a directory on the FTP server machine.

ftp_rmdir_ex

Deletes a directory on the FTP server machine for a specific session.

ftp_set_option

Sets options for an FTP session.


基本上每个函数都分两类,一类用于全局的session,一类用于指定session。例如对于FTP的DIR命令,可看到如下的区别:
// Run dir on the pub/test directory
ftp_dir("Ftp_Dir", "PATH=pub/test", ENDITEM, LAST);
// Run dir on the pub/test directory
ftp_dir_ex(&ftp, "Ftp_Dir", "PATH=pub/test", ENDITEM, LAST);
另外,在帮助文档中找到下面一个比较完整的例子,略为加了一些注解:
Action()
{
       double duration; // 持续时间
       unsigned long lSize, lDur;
       int i;
       FTP pFTP; // FTP的Session
       char * host = "myHost.mercury.com";  // FTP服务器
       char * user = "myHost\\charlotte";// FTP服务器中定义的用户名
       char * pwd = "lucas"; // 密码
       char * port = "21"; // FTP端口号
       char ftpURL[100];
       // 组合成FTP的URL字符串
       sprintf(ftpURL,"URL=ftp://%s:%s@%s:%s", user, pwd, host, port);
       lr_output_message("%s",ftpURL); // 输出URL
       //Action.c(18): URL=ftp://myHost\charlotte:lucas@myHost.mercury.com這個 E-mail 地址已經被防止灌水惡意程式保護,您需要啟用 Java Script. 才能觀看 :21
       /* 登录到FTP服务器 */
       ftp_logon_ex(&pFTP,"LogOn", ftpURL, LAST);
       // 打开FTP目录,例如 c:\inetput\ftproot\testFiles
       ftp_dir_ex(&pFTP,"T1", "PATH=/testFiles", ENDITEM, LAST);
       // 下载指定的文件
       ftp_get_ex(&pFTP,"Get_Small_File",
                 "SOURCE_PATH=/testFiles/web.fm",
                 "TARGET_PATH=d:/temp/ftpTest/web.fm",
                 "MODE=BINARY",
                 ENDITEM ,
                 LAST);
      
       // 取得下载持续时间
       duration= ftp_get_last_transfer_duration_ex(&pFTP);
       // 输出下载持续时间
       lr_output_message("Get_Small_File Transfer took %.3f milliseconds", duration);
       //Action.c(35): Get_Small_File Transfer took 10.000 milliseconds
      
       // 取得下载的详细信息
       ftp_get_last_download_details_ex(&pFTP, &lSize, &lDur);
       // 输出下载的详细信息
       lr_output_message("Get_Small_File Download of %d bytes took %d milliseconds", lSize, lDur);
       //Action.c(39): Get_Small_File Download of 4307 bytes took 180 milliseconds
      
       // 下载另外一个大的文件
       ftp_get_ex(&pFTP,"Get_Large_File",
              "SOURCE_PATH=/testFiles/no_src.exe",
              "TARGET_PATH=d:/temp/ftpTest/no_src.exe",
              "MODE=BINARY",
              ENDITEM ,
       LAST);
       duration= ftp_get_last_transfer_duration_ex(&pFTP);
       lr_output_message("Get_Large_File Transfer took %.3f milliseconds", duration);
       //Action.c(50): Get_Large_File Transfer took 600.000 milliseconds
       ftp_get_last_download_details_ex(&pFTP, &lSize, &lDur);
       lr_output_message("Transfer of %d bytes took %d milliseconds", lSize, lDur);
       //Action.c(54): Transfer of 5399569 bytes took 1782 milliseconds
       duration = ftp_get_last_handshake_duration_ex(&pFTP);
       lr_output_message("Handshake took %f milliseconds", duration);
       //Action.c(58): Handshake took 20.000000 milliseconds
      
       // 退出FTP服务器
       ftp_logout_ex(&pFTP);
       return 0;
}


TAG: ftp FTP LoadRunner Loadrunner

 

评分:0

我来说两句

我的栏目

日历

« 2024-03-27  
     12
3456789
10111213141516
17181920212223
24252627282930
31      

数据统计

  • 访问量: 126137
  • 日志数: 65
  • 建立时间: 2009-06-24
  • 更新时间: 2013-11-01

RSS订阅

Open Toolbar