Curl FTP connection pooling

时间:2016-08-31 18:17:17

标签: curl ftp

In my application I am executing curl.exe as external command to get list of files from an FTP folder. I need to scan multiple folders to the list so I am calling this command multiple times output the file listing into local directory.

curl ftp://my-ip:port/path/1234/ --user username:password --list-only -o C:\localfolder\1234.txt

curl ftp://my-ip:port/path/8910/ --user username:password --list-only -o C:\localfolder\8910.txt

So I will have 1 file per each directory. We can't use wild card pattern for listing files from all required directories as they have no pattern, just random integer numbers.

Most of the cases I will need to scan 200 directors but also in some cases a couple of thousands upto 9000 (which is maximum). I have no problem for it as it is working perfect without any issues. Except in some extreme cases I won't get list from 1 or 2 directories due to network glitch.

Now I am thinking of optimization. Two optimizations can be done here

My application level optimization: Instead of calling curl.exe so many times, I will create a dynamic bat file with multiple calls in it so my application will call it only once and batch file will have the actual curl calls.

Curl connection pooling: This is what I am looking if it is possible with curl.exe I read somewhere sometime ago that curl library has connection pooling support like in PHP but I am not sure if curl executable has that capability. It could be good performance improvement if I can utilize this feature if it has one.

1 个答案:

答案 0 :(得分:0)

根据cURL手册(在 PERSISTENT CONNECTIONS 一节中):

  

在单个命令行上指定多个文件将进行卷曲传输     所有这些,按照指定的顺序一个接一个地。

     

libcurl将尝试使用持久连接进行传输     第二次传输到同一主机可以使用相同的连接     已经启动并在之前的转移中保持开放状态。这很大     除了第一次转移之外,所有人都减少了连接时间     更好地利用网络。

来源:https://curl.haxx.se/docs/manual.html

这样的东西
curl --user username:password --list-only ftp://my-ip:port/path/1234/ -o C:\localfolder\1234.txt ftp://my-ip:port/path/8910/ -o C:\localfolder\8910.txt

应该做你想要的(2个或更多的URL)。