Logo Search packages:      
Sourcecode: jenkins-trilead-ssh2 version File versions  Download package

void com::trilead::ssh2::SFTPv3Client::write ( SFTPv3FileHandle  handle,
long  fileOffset,
byte[]  src,
int  srcoff,
int  len 
) throws IOException [inline]

Write bytes to a file. If len > 32768, then the write operation will be split into multiple writes.

Parameters:
handlea SFTPv3FileHandle handle.
fileOffsetoffset (in bytes) in the file.
srcthe source byte array.
srcoffoffset in the source byte array.
lenhow many bytes to write.
Exceptions:
IOException

Definition at line 1310 of file SFTPv3Client.java.

References receiveMessage().

Referenced by writeToFile().

      {
            checkHandleValidAndOpen(handle);

            while (len > 0)
            {
                  int writeRequestLen = len;

                  if (writeRequestLen > 32768)
                        writeRequestLen = 32768;

                  int req_id = generateNextRequestID();

                  TypesWriter tw = new TypesWriter();
                  tw.writeString(handle.fileHandle, 0, handle.fileHandle.length);
                  tw.writeUINT64(fileOffset);
                  tw.writeString(src, srcoff, writeRequestLen);

                  if (debug != null)
                  {
                        debug.println("Sending SSH_FXP_WRITE...");
                        debug.flush();
                  }

                  sendMessage(Packet.SSH_FXP_WRITE, req_id, tw.getBytes());

                  fileOffset += writeRequestLen;

                  srcoff += writeRequestLen;
                  len -= writeRequestLen;

                  byte[] resp = receiveMessage(34000);

                  TypesReader tr = new TypesReader(resp);

                  int t = tr.readByte();

                  int rep_id = tr.readUINT32();
                  if (rep_id != req_id)
                        throw new IOException("The server sent an invalid id field.");

                  if (t != Packet.SSH_FXP_STATUS)
                        throw new IOException("The SFTP server sent an unexpected packet type (" + t + ")");

                  int errorCode = tr.readUINT32();

                  if (errorCode == ErrorCodes.SSH_FX_OK)
                        continue;

                  String errorMessage = tr.readString();

                  throw new SFTPException(errorMessage, errorCode);
            }
      }

Here is the call graph for this function:

Here is the caller graph for this function:


Generated by  Doxygen 1.6.0   Back to index