Martijn Verburg skribis:

> I know how to create a gzipped file on the local file system by using
> the GZIPOutputStream class. Want I want to do is create a gzipped file
> on a remote file system by using the JSch SFTP methods.

Sounds reasonable.

> I've gzipped the byte[] of data and am passing that as an InputStream
> to the JSch library for SFTPing to a remote file directory (as a .gz
> file). However, the file that is delivered has a bad EOL character and
> cannot be 'gunzipped'. The SSCE is as follows:
> 
> byte[] content = "Content".getBytes();
> // Lots of work inside gzipContent method call
> // It does work (I promise!) returns a 'gzipped' byte[]
> byte[] gzippedContent = gzipContent(content);
> ByteArrayInputStream bais = new ByteArrayInputStream(gzippedContent);
> channelSftp.put(bais, "Content.txt.gz");

Looks good.

> The resulting file always has a bad EOL character.

A gzip file is binary, there are no EOL characters (there might be bytes
which are EOL characters under some (or most) interpretations, but you
should not try to interpret a gzip file as text.)
What are you doing here?
Could you post the full error message, if any?

If you write your gzippedContent locally on disk, does it work then?

If you upload a local gzip file with the put(String, String) method,
does it work?

Could you put both the locally written and the remote one on some
webspace and put a link here?  (Repeat it with a innocent content if
your one is some secret).

> I can't see of
> another method that would do the trick - which means I think I'm
> missing some fundamental point.

For me it looks like you are using the JSch API just fine, thus either
there is a bug in JSch which happens only on certain types of content or
your gzippedContent array is defect.
Or that you attend JSch or the ssh server to decompress your file while
it doesn't do anything like this.

> Or I might not be - apparently the JZlib sub lib with Jsch does not
> support the Gzip format, so it may not be possible to 'stream' a
> gzipped byte array using this library.

JSch (or the ChannelSftp, really) does (or at least should) neither
inspect nor alter the contents of your uploaded file. It will not be
automatically zipped or unzipped by JSch, it will just be transported as is.

The zlib compression is used on the transport layer, two layers below
what the sftp channel writes/sees.


PaĆ­lo

PS: For other readers: the same question is also on Stack Overflow:
http://stackoverflow.com/q/6232842/600500

Attachment: signature.asc
Description: OpenPGP digital signature

------------------------------------------------------------------------------
Simplify data backup and recovery for your virtual environment with vRanger.
Installation's a snap, and flexible recovery options mean your data is safe,
secure and there when you need it. Discover what all the cheering's about.
Get your free trial download today. 
http://p.sf.net/sfu/quest-dev2dev2 
_______________________________________________
JSch-users mailing list
JSch-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jsch-users

Reply via email to