login about faq

Hello, I'm downloading a TXT file via SFTP with command:

success = sftp.DownloadFileByName(remoteFilePath, localFilePath);

and it works but the file is missing of last chars. The log tell me the file is 4488 bytes, but really is 4522. Chilkat logs:

DownloadFileByName:
    DllDate: May 25 2017
    ChilkatVersion: 9.5.0.68
    UnlockPrefix: GLOCALSSH
    Architecture: Little Endian; 64-bit
    Language: .NET 4.5 / x64
    VerboseLogging: 1
    SshVersion: SSH-2.0-SSH
    SftpVersion: 3
    downloadFileByName:
        PreserveDate: 0
        fromFilePath: OUTPUT/AGOPT20170626.TXT
        toFilePath: D:\TEMP\ImportFlussi\OUTPUT\AGOPT20170626.TXT
        fromFilePathUtf8_QP: OUTPUT/AGOPT20170626.TXT
        toFilePathUtf8_QP: D:\TEMP\ImportFlussi\OUTPUT\AGOPT20170626.TXT
        OpenRemoteFile:
            sftpOpenFile:
                filepathUtf8_QP: OUTPUT/AGOPT20170626.TXT
                remotePath: OUTPUT/AGOPT20170626.TXT
                access: readOnly
                createDisposition: openExisting
                v3Flags: 0x1
                sendPacket:
                    channelSendData2:
                        (leaveContext)
                    (leaveContext)
                Sent FXP_OPEN
                readSftpPacket:
                    (leaveContext 93ms)
                handle: 2F4F55545055542F41474F505432303137303632362E545854
                (leaveContext 93ms)
            timeToOpenMs: Elapsed time: 93 millisec
            (leaveContext 93ms)
        FetchRemoteFileAttributes:
            fetchAttributes:
                bFollowLinks: 1
                bIsHandle: 0
                bSizeOnly: 1
                filename: OUTPUT/AGOPT20170626.TXT
                serverVersion: 3
                Using FXP_STAT
                sendPacket:
                    channelSendData2:
                        (leaveContext)
                    (leaveContext 16ms)
                Sent message to fetch attributes.
                readSftpPacket:
                    (leaveContext)
                Received SSH_FXP_ATTRS
                unpackFileAttr_v3:
                    validFlags: 0xd
                    size: 4488
                    permissions: 0x81ff
                    octalPermissions: 100777
                    type: 1
                    lastAccessTime32: 0x59511690
                    lastModifiedTime32: 0x59511690
                    (leaveContext)
                (leaveContext 16ms)
            timeToFetchAttrMs: Elapsed time: 16 millisec
            (leaveContext 16ms)
        remoteFileSize: 4488
        resumeFlag: 0
        openForReadWriteWin32:
            (leaveContext)
        numBytesToDownload: 4488
        soRcvBuf: 4194304
        soSndBuf: 262144
        cryptAlgorithm: aes
        macAlgorithm: SHA-1
        compression: no
        newDownloadLoop:
            offset64: 0
            numBytesToDownload: 4488
            readUntilEnd: 0
            sendFxpRead:
                sendPacket:
                    sendChannelData:
                        (leaveContext)
                    (leaveContext)
                (leaveContext)
            (leaveContext 78ms)
        sftpCloseHandle:
            handle: 2F4F55545055542F41474F505432303137303632362E545854
            sendPacket:
                channelSendData2:
                    (leaveContext)
                (leaveContext)
            Sent FXP_CLOSE
            readSftpPacket:
                (leaveContext 31ms)
            StatusResponseFromServer:
                Request: FXP_CLOSE
                InformationReceivedFromServer:
                    StatusCode: 0
                    StatusMessage: The operation completed
                    (leaveContext)
                (leaveContext)
            (leaveContext 31ms)
        timeToCloseHandleMs: Elapsed time: 31 millisec
        Closing local output file...
        Verifying local output file size...
        localFileSizeAfterDownload: 4488
        expectedFileSizeAfterDownload: 4488
        Good. The local file is the expected size.
        totalTimeMs: Elapsed time: 250 millisec
        (leaveContext 250ms)
    Success.
    (leaveContext 250ms)

Server Logs with filezilla client: 1 Filezilla asks 32768 bytes and get 4522 (really dimension) 2017-06-26 16:17:22,742 [Thread-140] INFO SPXPSshdLoggingListener - Remote client wants 32768 bytes from file at offset 0 localwindow=130817 remotewindow=2147483273 2017-06-26 16:17:22,742 [Thread-140] INFO SpecialLog - SFTPSERVERCMD: (xxxx@/xxxxxxx:50907) readFile /OUTPUT/AGOPT20170626.TXT 2017-06-26 16:17:22,742 [Thread-140] TRACE SFTPVirtualFileSystem - Entering SFTPVirtualFileSystem.readFile: 2017-06-26 16:17:22,742 [Thread-140] TRACE SFTPVirtualFileSystem - fileHandle: 2F4F55545055542F41474F505432303137303632362E545854 offset: 0 buf.length: 32785 start: 13 numBytesToRead: 32768 2017-06-26 16:17:22,742 [Thread-140] TRACE SFTPVirtualFileSystem - Exiting SFTPVirtualFileSystem.readFile: 2017-06-26 16:17:22,742 [Thread-140] TRACE SFTPVirtualFileSystem - SFTPVirtualFileSystem.readFile: Returning 4522 2017-06-26 16:17:22,742 [Thread-140] INFO SPXPSshdLoggingListener - Read 4522 bytes from filesystem …2017-06-26 16:17:23,117 [Thread-140] DEBUG SPXPSshdLoggingListener - SFTP_FILE_DOWNLOAD_COMPLETE| FILE_NAME = /OUTPUT/AGOPT20170626.TXT| SESSION_ID = [B@4f0bb37b| NFS = com.xxxxxxxxx.spxp.sftpserver.filesystem.SFTPVirtualFileSystem@38e07fc8| BYTES_TRANSFERED = 4522 SUCCESS

Serve logs with Chilkat library: 2 ChilkatDotNet45 v.9.5.0.61 asks 4488 bytes and get 4488 (not completed size!) 2017-06-26 16:17:55,211 [Thread-142] INFO SPXPSshdLoggingListener - Remote client wants 4488 bytes from file at offset 0 localwindow=130852 remotewindow=2096701 2017-06-26 16:17:55,211 [Thread-142] INFO SpecialLog - SFTPSERVERCMD: (SPZ-AXEROX@/172.30.193.146:50924) readFile /OUTPUT/AGOPT20170626.TXT 2017-06-26 16:17:55,211 [Thread-142] TRACE SFTPVirtualFileSystem - Entering SFTPVirtualFileSystem.readFile: 2017-06-26 16:17:55,211 [Thread-142] TRACE SFTPVirtualFileSystem - fileHandle: 2F4F55545055542F41474F505432303137303632362E545854 offset: 0 buf.length: 4505 start: 13 numBytesToRead: 4488 2017-06-26 16:17:55,211 [Thread-142] TRACE SFTPVirtualFileSystem - Exiting SFTPVirtualFileSystem.readFile: 2017-06-26 16:17:55,211 [Thread-142] TRACE SFTPVirtualFileSystem - SFTPVirtualFileSystem.readFile: Returning 4488 2017-06-26 16:17:55,211 [Thread-142] INFO SPXPSshdLoggingListener - Read 4488 bytes from filesystem 2017-06-26 16:17:55,258 [Thread-142] DEBUG SPXPSshdLoggingListener - SFTP_FILE_DOWNLOAD_COMPLETE| FILE_NAME = OUTPUT/AGOPT20170626.TXT| SESSION_ID = [B@77c16c5f| NFS = com.xxxxxxxx.spxp.sftpserver.filesystem.SFTPVirtualFileSystem@52e42811| BYTES_TRANSFERED = 4488 SUCCESS

asked Jul 10 at 04:08

Paolo%20Celoria's gravatar image

Paolo Celoria
11

edited Jul 10 at 04:47


The problem is SSH (SFTP) server tell to Chilkat wrong file size. So Chilkat download only a part.

A workaround using ReadFileByte could be:

 using (var fs = new FileStream(LocalDestinationFilename, FileMode.Create, FileAccess.Write))
            {
                string handle = sftp.OpenFile(RemoteFileName, "readOnly", "openExisting");
                while (!sftp.Eof(handle))
                {
                    byte[] byteArray = sftp.ReadFileBytes(handle, 131072);

                    fs.Write(byteArray, 0, byteArray.Length);
                }

            }
link

answered Jul 11 at 08:19

Paolo%20Celoria's gravatar image

Paolo Celoria
11

Paolo Celoria , could you tell us that you use which sftp server? Thanks.

link

answered Jul 11 at 16:04

muggle222's gravatar image

muggle222
183

Sorry, I have no access to server.

(Jul 12 at 02:32) Paolo Celoria

Paolo Celoria , you should know so chilkat will adapter it and we will do attention about it.

link

answered Jul 13 at 09:09

muggle222's gravatar image

muggle222
183

I discover that the number of missing chars at the end of file is equal to number of lines of the file. Probably passing from Linux SFTP to Windows (download with chilkat), the LF/CR were added to byte count and the download is stopped before the end! This coul help you? Thanks

link

answered Jul 19 at 05:19

Paolo%20Celoria's gravatar image

Paolo Celoria
11

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:

×226

Asked: Jul 10 at 04:08

Seen: 673 times

Last updated: Jul 26 at 08:02

powered by OSQA