login about faq
0
1

i am uploading a file using SFTP (SSH File Transfer Protocol). Using ActiveX the code is similar to:

//Open the file on the server for overwriting
handle = sftp.OpenFile(path, 'writeOnly', 'createTruncate');
if (handle = '') then
   throw new Exception();

//  Upload from the local file to the SSH server.
success = sftp.WriteFileBytes(handle, fileData);
if (success <> 1) then
   throw new Exception();

//Close the file.
success = sftp.CloseHandle(handle);
if (success <> 1) then
    throw new Exception();

This code all works fine and correct; even throwing an error if i don't have permission to overwrite the existing file. But when my account's Quota limit is exceeded, the upload appears to complete without error, but the file isn't actually accepted.

If i perform the same action manually using an SSTP client, i get the errors:

Cannot close remote file 'MyTestFile.dat'.

Permission denied.
Error code: 3
Error message from server (en): Permission denied
Request code: 4

If i upload a small enough file (or make some room on the server) the upload completes fine.

What terrifies me is that Chilkat doesn't give any error that the upload failed; either during the initial WriteFileBytes or during CloseHandle. The documentation for CloseHandle says that 1 indicates success:

function CloseHandle(handle: WideString): Integer;

Closes a file on the SSH/SFTP server. handle is a file handle returned from a previous call to OpenFile.
Returns 1 for success, 0 for failure.


i wondered if maybe it was a bug in WriteFileBytes, and that using something more like what WinSCP does, a file transfer, rather than writing bytes, would fix it. So i changed from

//  Upload from the local file to the SSH server.
success = sftp.WriteFileBytes(handle, fileData);

and first save the data to a temporary file, and call:

//  Upload from the local file to the SSH server.
success = sftp.UploadFile(handle, tempFile);

But the result is the same; no error.

i see in the verbose LastErrorText log when calling CloseHandle:

  packetType: SSH_FXP_STATUS    
  StatusResponseFromServer:     
    Request: FXP_CLOSE  
    InformationReceivedFromServer:  
      StatusCode: 3     
      StatusMessage: Permission denied  
    --InformationReceivedFromServer     
  --StatusResponseFromServer

So what i need is the fact that the upload failed.

The problem, of course, is that the local site will assume the transfer went fine. In reality the transfer failed. And government auditors don't care about technical reasons; they just issue fines for failing to comply with the law.


Edit:

  CloseHandle:  
    DllDate: Aug  5 2012    
    UnlockPrefix: JAMIEBSSH     
    Username: FS44:Avatar   
    Architecture: Little Endian; 32-bit     
    Language: ActiveX   
    VerboseLogging: 1   
    SshVersion: SSH-2.0-0   
    SftpVersion: 3  
    handle: 00000000    
    closeHandle:    
      handle: 00000000  
      sendPacket:   
        packetType: SSH_FXP_CLOSE   
        sendMessage: CHANNEL_DATA   
      --sendPacket  
      Sent FXP_CLOSE    
      loopIdx: 1    
      readChannelData_2:    
        readChannelData: chan=0; tmOutMs=0; checkQ=1; onlyExt=0; skipExt=1; idleTmOutMs=0; bOneRaw=0    
        genRead_1:  
          packetLen: 60     
          mType: CHANNEL_DATA   
          payload: msgType=94; len=49   
        --genRead_1     
      --readChannelData_2   
      packetType: SSH_FXP_STATUS    
      StatusResponseFromServer:     
        Request: FXP_CLOSE  
        InformationReceivedFromServer:  
          StatusCode: 3     
          StatusMessage: Permission denied  
        --InformationReceivedFromServer     
      --StatusResponseFromServer    
    --closeHandle   
    Success.    
  --CloseHandle `enter code here`

asked Oct 24 '12 at 16:54

Ian%20Boyd's gravatar image

Ian Boyd
6124

edited Oct 24 '12 at 16:57


Thanks! It sounds to me like the call to WriteFileBytes succeeds, meaning that the server accepts the data and there's no way for the client to tell that anything is amiss (or will be amiss). However, the CloseHandle method definitely failed, and CloseHandle should have returned a failed status of 0.

I found and fixed the problem in CloseHandle. Here is a new build: http://www.chilkatsoft.com/preRelease/ChilkatSsh.zip

link

answered Oct 24 '12 at 17:39

chilkat's gravatar image

chilkat ♦♦
11.8k316358420

Tested, and deployed, and that fixed it. Thank you sir!

(Oct 24 '12 at 20:37) Ian Boyd
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or __italic__
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×200

Asked: Oct 24 '12 at 16:54

Seen: 5,362 times

Last updated: Oct 24 '12 at 20:37

powered by OSQA