我正在尝试重现一个问题,其中某些客户端在使用SFTP协议下载时会收到错误的文件内容。
根据我们的SFTP服务器(CrushFTP)日志,他们可能会在一个会话中打开多个文件,然后使用一些流水线来下载文件。我不知道他们使用哪种类型的库,因为他们为此使用了一些SAAS提供程序。
我正在尝试使用libssh2重现此行为,但是sftp_read() internal error在第一个打开文件异步返回LIBSSH2_ERROR_EAGAIN后,在第二个打开的文件上异步调用libssh2_sftp_read时,即使在本地主机连接到OpenSSH时,也遇到了问题。
在浏览SSH文件传输协议IETF草案时,我可以看到该协议允许同时打开多个文件并使用多个SSH_FXP_READ请求请求其内容,而无需等待响应。
以下是我用于测试的代码(SSCCE,但是很长-C非常冗长)-使用以下代码进行编译gcc sftp_multifile.c -lssh2 -Wall -g -o sftp_multifile和测试:
./sftp_multifile localhost 22 testusername testpassword /usr/share/dict/words /usr/share/doc/words/readme.txt
connect try: ai_family=10 ai_socktype=1 ai_protocol=6 addr=::1 port=22
opening: /usr/share/dict/words
opening: /usr/share/doc/words/readme.txt
reading: /usr/share/dict/words from 10134400 to 140736927200896
read result: -37
reading: /usr/share/doc/words/readme.txt from 10135536 to 140736927201920
read result: -31
Bad read result: -31
Read error: /usr/share/doc/words/readme.txt: sftp_read() internal error
Run Code Online (Sandbox Code Playgroud)
我是否在代码中出错了?或者libssh2是否仅不支持对多个打开的文件进行libssh2_sftp_read管道传输?或者可能只是libssh2中的错误应报告给其维护者?
#include <libssh2.h>
#include <libssh2_sftp.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#include <stdio.h>
#include <stdlib.h> …Run Code Online (Sandbox Code Playgroud) 我需要写一个模板函数replace_all在C++中,这将需要一个字符串,wstring的,glibmm :: ustring等,并更换所有出现search在subject用replace.
replace_all.cc
template < class T >
T replace_all(
T const &search,
T const &replace,
T const &subject
) {
T result;
typename T::size_type done = 0;
typename T::size_type pos;
while ((pos = subject.find(search, done)) != T::npos) {
result.append (subject, done, pos - done);
result.append (replace);
done = pos + search.size ();
}
result.append(subject, done, subject.max_size());
return result;
}
Run Code Online (Sandbox Code Playgroud)
test.cc
#include <iostream>
template < class T >
T replace_all(
T …Run Code Online (Sandbox Code Playgroud) 我在perl中编程并且与postgres数据库有一个现有的连接(progammatically).建立连接后,我不控制连接代码,我想将自动提交设置为关闭.
怎么做到这一点?当我以交互方式进行时,我看不到任何变化.我设置了autocommit然后执行插入,我看到了更改.我做回滚,我得到的是没有交易存在.
我想设置autocommit,做我的工作,然后提交.如何通过现有连接实现这一目标?
谢谢Reza