[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: sftp_read receives EOF on second call for a 24kb file


On Wednesday 23 October 2013 09:53:28 Andreas Schneider wrote:
> On Tuesday 22 October 2013 18:58:17 Darren wrote:
> >  Hi Kevin,
> > 
> > Assuming remote to local transfer:
> > 
> > You read the first chunk of data, and use sftp_seek to move the file
> > pointer
> There is absolutely no need to call sftp_seek() you only need it if you
> resume a transfer. The API works the same way as the POSIX API. Files
> should be transferred in small chunks.

There is a bug in the code :)

> #define MAX_XFER_BUF_SIZE 16384
> 
> char buf[MAX_XFER_BUF_SIZE];
> 
> file = sftp_open(sftp, path, O_RDONLY, 0);
> 
> for (;;) {
> 	bytesread = sftp_read(file, buf, MAX_XFER_BUF_SIZE);
> 	if (bytesread == 0) {
> 		break; /* EOF */
> 	} else if (bytesread < 0) {
> 		/* ERROR HANDLING */
> 	}
> 
> 	byteswritten = write(fd, buf, MAX_XFER_BUF_SIZE)

	byteswritten = write(fd, buf, bytesread)

> 	if (byteswritten != bytesread) {
> 		/* ERROR */
> 	}
> }
> 
> This way I can transfer files which are several gigabyte of size.
> 
> 
> 	-- andreas

-- 
Andreas Schneider                   GPG-ID: CC014E3D
www.cryptomilk.org                asn@xxxxxxxxxxxxxx


References:
Re: sftp_read receives EOF on second call for a 24kb fileDarren <d.tomlin@xxxxxxxxxxxx>
Re: sftp_read receives EOF on second call for a 24kb fileAndreas Schneider <asn@xxxxxxxxxxxxxx>
Archive administrator: postmaster@lists.cynapses.org