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=00000000}, 12) = 0
getsockname(3, {sa_family=AF_NETLINK, pid=6499, groups=00000000}, [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=00000000}, 12) = 20
recvmsg(3, {msg_name(12)={sa_family=AF_NETLINK, pid=0, groups=00000000},
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=00000000},
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=00000000},
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=00000000}, 12) = 0
getsockname(4, {sa_family=AF_NETLINK, pid=6499, groups=00000000}, [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=00000000}, 12) = 20
recvmsg(4, {msg_name(12)={sa_family=AF_NETLINK, pid=0, groups=00000000},
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=00000000},
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=00000000},
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) = 4
connect(4, {sa_family=AF_INET, sin_port=htons(1097),
sin_addr=inet_addr("192.168.1.34")}, 16) = -1 EINPROGRESS (Operation now in
progress)
getsockopt(4, SOL_SOCKET, SO_ERROR, [0], [4]) = 0
recv(3, "150 Opening BINARY mode data con"..., 8192, MSG_DONTWAIT) = 51
send(4, ".0.1.2.3.4.5.6.7.8.9.10.11.12.13"..., 8192, MSG_DONTWAIT) = 8192
send(4, "860.1861.1862.1863.1864.1865.186"..., 8192, MSG_DONTWAIT) = 8192
send(4, "8.3499.3500.3501.3502.3503.3504."..., 8192, MSG_DONTWAIT) = 8192
send(4, "5137.5138.5139.5140.5141.5142.51"..., 8192, MSG_DONTWAIT) = 8192
send(4, "75.6776.6777.6778.6779.6780.6781"..., 8192, MSG_DONTWAIT) = 3432
send(4, ".7462.7463.7464.7465.7466.7467.7"..., 8192, MSG_DONTWAIT) = -1
EAGAIN (Resource temporarily unavailable)
send(4, ".7462.7463.7464.7465.7466.7467.7"..., 8192, MSG_DONTWAIT) = 8192
send(4, "100.9101.9102.9103.9104.9105.910"..., 8192, MSG_DONTWAIT) = 8192
send(4, "0.951.952.953.954.955.956.957.95"..., 8192, MSG_DONTWAIT) = 8192
send(4, ".2599.2600.2601.2602.2603.2604.2"..., 8192, MSG_DONTWAIT) = 8192
send(4, "237.4238.4239.4240.4241.4242.424"..., 8192, MSG_DONTWAIT) = 3432
send(4, "3.4924.4925.4926.4927.4928.4929."..., 8192, MSG_DONTWAIT) = 8192
send(4, "6562.6563.6564.6565.6566.6567.65"..., 8192, MSG_DONTWAIT) = 8192
send(4, "00.8201.8202.8203.8204.8205.8206"..., 8192, MSG_DONTWAIT) = 8192
send(4, ".9839.9840.9841.9842.9843.9844.9"..., 8192, MSG_DONTWAIT) = 7280
send(4, "6.1517.1518.1519.1520.1521.1522."..., 8192, MSG_DONTWAIT) = -1
EAGAIN (Resource temporarily unavailable)
send(4, "6.1517.1518.1519.1520.1521.1522."..., 8192, MSG_DONTWAIT) = 8192
send(4, "3155.3156.3157.3158.3159.3160.31"..., 8192, MSG_DONTWAIT) = 8192
send(4, "93.4794.4795.4796.4797.4798.4799"..., 8192, MSG_DONTWAIT) = 8192
send(4, ".6432.6433.6434.6435.6436.6437.6"..., 8192, MSG_DONTWAIT) = 8192
send(4, "070.8071.8072.8073.8074.8075.807"..., 8192, MSG_DONTWAIT) = 8192
send(4, "8.9709.9710.9711.9712.9713.9714."..., 8192, MSG_DONTWAIT) = 8192
send(4, ".1569.1570.1571.1572.1573.1574.1"..., 8192, MSG_DONTWAIT) = 8192
send(4, "207.3208.3209.3210.3211.3212.321"..., 8192, MSG_DONTWAIT) = 6368
send(4, ".4481.4482.4483.4484.4485.4486.4"..., 8192, MSG_DONTWAIT) = -1
EAGAIN (Resource temporarily unavailable)
send(4, ".4481.4482.4483.4484.4485.4486.4"..., 8192, MSG_DONTWAIT) = 8192
send(4, "119.6120.6121.6122.6123.6124.612"..., 8192, MSG_DONTWAIT) = 8192
send(4, "7.7758.7759.7760.7761.7762.7763."..., 8192, MSG_DONTWAIT) = 8192
send(4, "9396.9397.9398.9399.9400.9401.94"..., 8192, MSG_DONTWAIT) = 8192
send(4, "256.1257.1258.1259.1260.1261.126"..., 8192, MSG_DONTWAIT) = 8192
send(4, "4.2895.2896.2897.2898.2899.2900."..., 8192, MSG_DONTWAIT) = 8192
send(4, "4533.4534.4535.4536.4537.4538.45"..., 8192, MSG_DONTWAIT) = 8192
send(4, "71.6172.6173.6174.6175.6176.6177"..., 8192, MSG_DONTWAIT) = 6368
send(4, "7445.7446.7447.7448.7449.7450.74"..., 8192, MSG_DONTWAIT) = 8192
send(4, "83.9084.9085.9086.9087.9088.9089"..., 8192, MSG_DONTWAIT) = 8192
send(4, "9.930.931.932.933.934.935.936.93"..., 8192, MSG_DONTWAIT) = 8192
send(4, "2582.2583.2584.2585.2586.2587.25"..., 8192, MSG_DONTWAIT) = 8192
send(4, "20.4221.4222.4223.4224.4225.4226"..., 8192, MSG_DONTWAIT) = 8192
send(4, ".5859.5860.5861.5862.5863.5864.5"..., 8192, MSG_DONTWAIT) = 8192
send(4, "497.7498.7499.7500.7501.7502.750"..., 8192, MSG_DONTWAIT) = 8192
send(4, "5.9136.9137.9138.9139.9140.9141."..., 4322, MSG_DONTWAIT) = 4322
Written: 0293346\n
send(3, "QUIT\r\n", 6, MSG_DONTWAIT)    = 6




-- 
Edit bug report at http://bugs.php.net/?id=50962&edit=1
-- 
Try a snapshot (PHP 5.2):            
http://bugs.php.net/fix.php?id=50962&r=trysnapshot52
Try a snapshot (PHP 5.3):            
http://bugs.php.net/fix.php?id=50962&r=trysnapshot53
Try a snapshot (PHP 6.0):            
http://bugs.php.net/fix.php?id=50962&r=trysnapshot60
Fixed in SVN:                        
http://bugs.php.net/fix.php?id=50962&r=fixed
Fixed in SVN and need be documented: 
http://bugs.php.net/fix.php?id=50962&r=needdocs
Fixed in release:                    
http://bugs.php.net/fix.php?id=50962&r=alreadyfixed
Need backtrace:                      
http://bugs.php.net/fix.php?id=50962&r=needtrace
Need Reproduce Script:               
http://bugs.php.net/fix.php?id=50962&r=needscript
Try newer version:                   
http://bugs.php.net/fix.php?id=50962&r=oldversion
Not developer issue:                 
http://bugs.php.net/fix.php?id=50962&r=support
Expected behavior:                   
http://bugs.php.net/fix.php?id=50962&r=notwrong
Not enough info:                     
http://bugs.php.net/fix.php?id=50962&r=notenoughinfo
Submitted twice:                     
http://bugs.php.net/fix.php?id=50962&r=submittedtwice
register_globals:                    
http://bugs.php.net/fix.php?id=50962&r=globals
PHP 4 support discontinued:          http://bugs.php.net/fix.php?id=50962&r=php4
Daylight Savings:                    http://bugs.php.net/fix.php?id=50962&r=dst
IIS Stability:                       
http://bugs.php.net/fix.php?id=50962&r=isapi
Install GNU Sed:                     
http://bugs.php.net/fix.php?id=50962&r=gnused
Floating point limitations:          
http://bugs.php.net/fix.php?id=50962&r=float
No Zend Extensions:                  
http://bugs.php.net/fix.php?id=50962&r=nozend
MySQL Configuration Error:           
http://bugs.php.net/fix.php?id=50962&r=mysqlcfg

Reply via email to