#50962 [NoF-Opn]: Using a ftp stream to a windows ftp server to upload results in missing data

2010-02-23 Thread m dot ebbers at i-real dot nl
 ID:   50962
 User updated by:  m dot ebbers at i-real dot nl
 Reported By:  m dot ebbers at i-real dot nl
-Status:   No Feedback
+Status:   Open
 Bug Type: Streams related
 Operating System: Linux
 PHP Version:  5.3.1
 New Comment:

I've tested it with the given snapshot:
PHP 5.3.3-dev (cli) (built: Feb 23 2010 08:21:46) 
Copyright (c) 1997-2010 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies

With the same results. Files are not always complete. :(


Previous Comments:


[2010-02-21 01:00:01] php-bugs at lists dot php dot net

No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to Open.



[2010-02-13 21:49:40] j...@php.net

Please try using this snapshot:

  http://snaps.php.net/php5.3-latest.tar.gz
 
For Windows:

  http://windows.php.net/snapshots/





[2010-02-08 09:29:16] m dot ebbers at i-real dot nl

Description:

When fopen/fwrite are used to upload a file, through ftp to a ftp
server running on windows, it is not always uploaded completely despite
the fact that fwrite returns that all bytes of the file are written.

I've testen the following scenarios with the attached code:
From Ubuntu 9.10 to Bulletproof ftpd under windows xp (vmware).
(failed)
From Ubuntu 9.10 to Serv-u ftpd under windows xp (vmware). (failed)
From Ubuntu 9.10 to vsftpd on same machine. (ok)
Different hardware and network:
From CentOS release 5 to Bulletproof ftpd on windows server (failed)

When using the ftp command it all works great.

Also tried the build-in ftp client from php and that works fine. It
only failed when using fopen/fwrite/file_put_contents.


Reproduce code:
---
$host = '192.168.1.34';
$user = 'marke';
$passwd = 'ebbers';
$path = '/';
$file = $argv[1];
$url='ftp://'.$user.':'.$passwd.'@'.$host.$path.$file;

$content = file_get_contents($file);
$handle = fopen($url, 'w');
$written = 0;

while ($written != strlen($content))
{

$write = fwrite($handle, substr($content, $written));
fflush($handle);
if($write){
$written .= $write;
echo Written: .$written.'\n';
}else{
break;
}
}

Expected result:

Output script: Written: 293346 (Test file is 293346 bytes.)
And a file on the ftp server of the same size.

Actual result:
--
Output script: Written: 293346 (Test file is 293346 bytes.)
A file on the server, but it is smaller. (and the sizes varies)

I've also a wireshark sniff available. The strange thing in the sniff
is that the every byte of the file is actually send, but by an unknown
reason there is tcp resend and the data in that resend is also the last
data in the file on the server.

Strace:
socket(PF_INET6, SOCK_DGRAM, IPPROTO_IP) = 3
socket(PF_NETLINK, SOCK_RAW, 0) = 3
bind(3, {sa_family=AF_NETLINK, pid=0, groups=}, 12) = 0
getsockname(3, {sa_family=AF_NETLINK, pid=6499, groups=}, [12])
= 0
sendto(3, \24\0\0\0\26\0\1\3\220\321oK\0\0\0\0\0\0\0\0, 20, 0,
{sa_family=AF_NETLINK, pid=0, groups=}, 12) = 20
recvmsg(3, {msg_name(12)={sa_family=AF_NETLINK, pid=0,
groups=},
msg_iov(1)=[{0\0\0\0\24\0\2\0\220\321oKc\31\0\0\2\10\200\376\1\0\0\0\10\0\1\0\177\0\0\1...,
4096}], msg_controllen=0, msg_flags=0}, 0) = 228
recvmsg(3, {msg_name(12)={sa_family=AF_NETLINK, pid=0,
groups=},
msg_iov(1)=[{@\0\0\0\24\0\2\0\220\321oKc\31\0\0\n\200\200\376\1\0\0\0\24\0\1\0\0\0\0\0...,
4096}], msg_controllen=0, msg_flags=0}, 0) = 256
recvmsg(3, {msg_name(12)={sa_family=AF_NETLINK, pid=0,
groups=},
msg_iov(1)=[{\24\0\0\0\3\0\2\0\220\321oKc\31\0\0\0\0\0\0\1\0\0\0\24\0\1\0\0\0\0\0...,
4096}], msg_controllen=0, msg_flags=0}, 0) = 20
socket(PF_INET, SOCK_STREAM, IPPROTO_IP) = 3
connect(3, {sa_family=AF_INET, sin_port=htons(21),
sin_addr=inet_addr(192.168.1.34)}, 16) = -1 EINPROGRESS (Operation now
in progress)
getsockopt(3, SOL_SOCKET, SO_ERROR, [0], [4]) = 0
recv(3, 220 Serv-U FTP Server v9.3 ready..., 8192, MSG_DONTWAIT) =
37
send(3, USER marke\r\n, 12, MSG_DONTWAIT) = 12
recv(3, 331 User name okay, need passwor..., 8192, MSG_DONTWAIT) =
36
send(3, PASS ebbers\r\n, 13, MSG_DONTWAIT) = 13
recv(3, 230 User logged in, proceed.\r\n, 8192, MSG_DONTWAIT) = 30
send(3, TYPE I\r\n, 8, MSG_DONTWAIT)  = 8
recv(3, 200 Type set to I.\r\n, 8192, MSG_DONTWAIT) = 20
send(3, SIZE /bin2\r\n, 12, MSG_DONTWAIT) = 12
recv(3, 550 /bin2: No such file.\r\n, 8192, MSG_DONTWAIT) = 26
send(3, EPSV\r\n, 6, MSG_DONTWAIT)= 6
recv(3, 500 'EPSV': command not understo..., 8192, MSG_DONTWAIT) =
37
send(3, PASV\r\n, 6, MSG_DONTWAIT

#50962 [NEW]: Using a ftp stream to a windows ftp server to upload results in missing data

2010-02-08 Thread m dot ebbers at i-real dot nl
From: m dot ebbers at i-real dot nl
Operating system: Linux
PHP version:  5.3.1
PHP Bug Type: Streams related
Bug description:  Using a ftp stream to a windows ftp server to upload results 
in missing data

Description:

When fopen/fwrite are used to upload a file, through ftp to a ftp server
running on windows, it is not always uploaded completely despite the fact
that fwrite returns that all bytes of the file are written.

I've testen the following scenarios with the attached code:
From Ubuntu 9.10 to Bulletproof ftpd under windows xp (vmware). (failed)
From Ubuntu 9.10 to Serv-u ftpd under windows xp (vmware). (failed)
From Ubuntu 9.10 to vsftpd on same machine. (ok)
Different hardware and network:
From CentOS release 5 to Bulletproof ftpd on windows server (failed)

When using the ftp command it all works great.

Also tried the build-in ftp client from php and that works fine. It only
failed when using fopen/fwrite/file_put_contents.


Reproduce code:
---
$host = '192.168.1.34';
$user = 'marke';
$passwd = 'ebbers';
$path = '/';
$file = $argv[1];
$url='ftp://'.$user.':'.$passwd.'@'.$host.$path.$file;

$content = file_get_contents($file);
$handle = fopen($url, 'w');
$written = 0;

while ($written != strlen($content))
{

$write = fwrite($handle, substr($content, $written));
fflush($handle);
if($write){
$written .= $write;
echo Written: .$written.'\n';
}else{
break;
}
}

Expected result:

Output script: Written: 293346 (Test file is 293346 bytes.)
And a file on the ftp server of the same size.

Actual result:
--
Output script: Written: 293346 (Test file is 293346 bytes.)
A file on the server, but it is smaller. (and the sizes varies)

I've also a wireshark sniff available. The strange thing in the sniff is
that the every byte of the file is actually send, but by an unknown reason
there is tcp resend and the data in that resend is also the last data in
the file on the server.

Strace:
socket(PF_INET6, SOCK_DGRAM, IPPROTO_IP) = 3
socket(PF_NETLINK, SOCK_RAW, 0) = 3
bind(3, {sa_family=AF_NETLINK, pid=0, groups=}, 12) = 0
getsockname(3, {sa_family=AF_NETLINK, pid=6499, groups=}, [12]) =
0
sendto(3, \24\0\0\0\26\0\1\3\220\321oK\0\0\0\0\0\0\0\0, 20, 0,
{sa_family=AF_NETLINK, pid=0, groups=}, 12) = 20
recvmsg(3, {msg_name(12)={sa_family=AF_NETLINK, pid=0, groups=},
msg_iov(1)=[{0\0\0\0\24\0\2\0\220\321oKc\31\0\0\2\10\200\376\1\0\0\0\10\0\1\0\177\0\0\1...,
4096}], msg_controllen=0, msg_flags=0}, 0) = 228
recvmsg(3, {msg_name(12)={sa_family=AF_NETLINK, pid=0, groups=},
msg_iov(1)=[{@\0\0\0\24\0\2\0\220\321oKc\31\0\0\n\200\200\376\1\0\0\0\24\0\1\0\0\0\0\0...,
4096}], msg_controllen=0, msg_flags=0}, 0) = 256
recvmsg(3, {msg_name(12)={sa_family=AF_NETLINK, pid=0, groups=},
msg_iov(1)=[{\24\0\0\0\3\0\2\0\220\321oKc\31\0\0\0\0\0\0\1\0\0\0\24\0\1\0\0\0\0\0...,
4096}], msg_controllen=0, msg_flags=0}, 0) = 20
socket(PF_INET, SOCK_STREAM, IPPROTO_IP) = 3
connect(3, {sa_family=AF_INET, sin_port=htons(21),
sin_addr=inet_addr(192.168.1.34)}, 16) = -1 EINPROGRESS (Operation now in
progress)
getsockopt(3, SOL_SOCKET, SO_ERROR, [0], [4]) = 0
recv(3, 220 Serv-U FTP Server v9.3 ready..., 8192, MSG_DONTWAIT) = 37
send(3, USER marke\r\n, 12, MSG_DONTWAIT) = 12
recv(3, 331 User name okay, need passwor..., 8192, MSG_DONTWAIT) = 36
send(3, PASS ebbers\r\n, 13, MSG_DONTWAIT) = 13
recv(3, 230 User logged in, proceed.\r\n, 8192, MSG_DONTWAIT) = 30
send(3, TYPE I\r\n, 8, MSG_DONTWAIT)  = 8
recv(3, 200 Type set to I.\r\n, 8192, MSG_DONTWAIT) = 20
send(3, SIZE /bin2\r\n, 12, MSG_DONTWAIT) = 12
recv(3, 550 /bin2: No such file.\r\n, 8192, MSG_DONTWAIT) = 26
send(3, EPSV\r\n, 6, MSG_DONTWAIT)= 6
recv(3, 500 'EPSV': command not understo..., 8192, MSG_DONTWAIT) = 37
send(3, PASV\r\n, 6, MSG_DONTWAIT)= 6
recv(3, 227 Entering Passive Mode (192,1..., 8192, MSG_DONTWAIT) = 47
send(3, STOR /bin2\r\n, 12, MSG_DONTWAIT) = 12
socket(PF_NETLINK, SOCK_RAW, 0) = 4
bind(4, {sa_family=AF_NETLINK, pid=0, groups=}, 12) = 0
getsockname(4, {sa_family=AF_NETLINK, pid=6499, groups=}, [12]) =
0
sendto(4, \24\0\0\0\26\0\1\3\220\321oK\0\0\0\0\0\0\0\0, 20, 0,
{sa_family=AF_NETLINK, pid=0, groups=}, 12) = 20
recvmsg(4, {msg_name(12)={sa_family=AF_NETLINK, pid=0, groups=},
msg_iov(1)=[{0\0\0\0\24\0\2\0\220\321oKc\31\0\0\2\10\200\376\1\0\0\0\10\0\1\0\177\0\0\1...,
4096}], msg_controllen=0, msg_flags=0}, 0) = 228
recvmsg(4, {msg_name(12)={sa_family=AF_NETLINK, pid=0, groups=},
msg_iov(1)=[{@\0\0\0\24\0\2\0\220\321oKc\31\0\0\n\200\200\376\1\0\0\0\24\0\1\0\0\0\0\0...,
4096}], msg_controllen=0, msg_flags=0}, 0) = 256
recvmsg(4, {msg_name(12)={sa_family=AF_NETLINK, pid=0, groups=},
msg_iov(1)=[{\24\0\0\0\3\0\2\0\220\321oKc\31\0\0\0\0\0\0\1\0\0\0\24\0\1\0\0\0\0\0...,
4096}], msg_controllen=0, msg_flags