Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

暗号化を有効にするとftpサーバーに接続できない #17

Closed
sayurin opened this Issue Apr 9, 2018 · 2 comments

Comments

Projects
None yet
1 participant
@sayurin
Copy link
Collaborator

sayurin commented Apr 9, 2018

ロリポップで提供されるftpサーバーに対して、暗号化なしでは接続できるが、暗号化ありでは右のリストが表示されない。

https://twitter.com/6ka6ka/status/983227793159831552
https://twitter.com/6ka6ka/status/983228318722871297
image

さくらレンタルサーバーでも同様の現象が発生するとのこと
https://twitter.com/skuromaku/status/983612090890899457

@sayurin sayurin added the bug label Apr 9, 2018

@sayurin sayurin added this to the v3.1 milestone Apr 9, 2018

@sayurin

This comment has been minimized.

Copy link
Collaborator Author

sayurin commented Apr 9, 2018

接続してみたものの、私の環境からは成功してしまった…。

>FEAT
211-Features:
 MDTM
 MFMT
 TVFS
 AUTH TLS
 MFF modify;UNIX.group;UNIX.mode;
 MLST modify*;perm*;size*;type*;unique*;UNIX.group*;UNIX.mode*;UNIX.owner*;
 PBSZ
 PROT
 REST STREAM
 SIZE
211 End
>TYPE A
200 Type set to A
>PASV
227 Entering Passive Mode (157,7,105,200,253,233).
Connecting for download to host 157.7.105.200 (65001). (TCP/IPv4)
Connected. (TCP/IPv4)
>MLSD
150 Opening ASCII mode data connection for MLSD
226 Transfer complete
Download file list successful. (374 Bytes)
Determination result of the filename Kanji code is UTF-8.
>XPWD
257 "/" is the current directory
>TYPE A
200 Type set to A
>PASV
227 Entering Passive Mode (157,7,105,200,254,39).
Connecting for download to host 157.7.105.200 (65063). (TCP/IPv4)
Connected. (TCP/IPv4)
>MLSD
150 Opening ASCII mode data connection for MLSD
226 Transfer complete
Download file list successful. (374 Bytes)
@sayurin

This comment has been minimized.

Copy link
Collaborator Author

sayurin commented Apr 9, 2018

受信中にABORで中止するのはdo_recvその先のFTPS_recvSOCKET_ERRORを返した場合でこの辺り。TODOコメントしてある通りにSEC_E_INCOMPLETE_MESSAGEが発生していた可能性が高い。

https://github.com/sayurin/ffftp/blob/v3.0/socket.cpp#L353-L387

static int FTPS_recv(SOCKET s, char* buf, int len, int flags) {
	assert(flags == 0 || flags == MSG_PEEK);
	auto context = getContext(s);
	if (!context)
		return recv(s, buf, len, flags);

	if (empty(context->readPlain)) {
		auto offset = size_as<int>(context->readRaw);
		context->readRaw.resize(context->streamSizes.cbHeader + context->streamSizes.cbMaximumMessage + context->streamSizes.cbTrailer);
		auto read = recv(s, data(context->readRaw) + offset, size_as<int>(context->readRaw) - offset, 0);
		if (read <= 0) {
			context->readRaw.resize(offset);
#ifdef _DEBUG
			if (read == 0)
				_RPTW0(_CRT_WARN, L"FTPS_recv recv: connection closed.\n");
			else if (auto lastError = WSAGetLastError(); lastError != WSAEWOULDBLOCK)
				_RPTWN(_CRT_WARN, L"FTPS_recv recv error: %d.\n", lastError);
#endif
			return read;
		}
		_RPTWN(_CRT_WARN, L"FTPS_recv recv: %d bytes.\n", read);
		context->readRaw.resize(offset + read);
		context->Decypt();
	}

	if (empty(context->readPlain))
		// TODO: recv()の読み出し量が少ないとSEC_E_INCOMPLETE_MESSAGEが発生してしまう。
		return context->readStatus == SEC_I_CONTEXT_EXPIRED ? 0 : SOCKET_ERROR;
	len = std::min(len, size_as<int>(context->readPlain));
	std::copy_n(begin(context->readPlain), len, buf);
	if ((flags & MSG_PEEK) == 0)
		context->readPlain.erase(begin(context->readPlain), begin(context->readPlain) + len);
	_RPTWN(_CRT_WARN, L"FTPS_recv read: %d bytes.\n", len);
	return len;
}

@sayurin sayurin changed the title ロリポップのftpサーバーに接続できない 暗号化を有効にするとftpサーバーに接続できない Apr 10, 2018

@sayurin sayurin closed this in 874ec9d Apr 10, 2018

sayurin added a commit that referenced this issue Apr 10, 2018

@sayurin sayurin referenced this issue Feb 8, 2019

Merged

#17 の修正 #19

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.