0 votes
by (120 points)
edited

Hello All,

I have a Windows Client using Rebex SFTP to copy zip files into Unix Server's directory. I have code like following

 Sftp sftpclient = new Sftp();
 sftpclient.Encoding = System.Text.Encoding.UTF8;
 SshParameters sshParams = new SshParameters();
 sshParams.Compression = false;
 sshParams.EncryptionAlgorithms = SshEncryptionAlgorithm.AES;
 sshParams.KeyExchangeAlgorithms = SshKeyExchangeAlgorithm.Any;

 sftpclient.TransferType = SftpTransferType.Binary;
 sftpclient.Connect("Host", Sftp.DefaultPort, sshParams);

Zip files are moving to Unix Server but when zip files are open it throws following error:

The compressed size stored in the local header for this file is not the same as the compressed size stored in the central header

I don't anything how to start dig this problem, can anyone help?

Cheers,

Michael

Log file is below and Copying code after that

2010-12-15 16:09:59.756 Opening log file.
2010-12-15 16:09:59.787 INFO Sftp(1) Info: Connecting to ip-address:22 using Sftp 2.0.3854.0.
2010-12-15 16:09:59.849 DEBUG Sftp(1) SSH: Server is 'SSH-2.0-1.36_sshlib GlobalSCAPE'.
2010-12-15 16:09:59.865 DEBUG Sftp(1) SSH: Negotiation started.
2010-12-15 16:09:59.928 DEBUG Sftp(1) SSH: Group exchange.
2010-12-15 16:10:00.084 DEBUG Sftp(1) SSH: Negotiating key.
2010-12-15 16:10:00.256 DEBUG Sftp(1) SSH: Validating signature.
2010-12-15 16:10:00.287 DEBUG Sftp(1) SSH: Negotiation finished.
2010-12-15 16:10:00.287 INFO Sftp(1) Info: Server: SSH-2.0-1.36_sshlib GlobalSCAPE
2010-12-15 16:10:00.287 INFO Sftp(1) Info: Fingerprint: f1:ce:62:76:81:0d:32:c5:2d:fc:ec:60:39:7f:5d:72
2010-12-15 16:10:00.303 INFO Sftp(1) Info: Cipher info: SSH 2.0, DiffieHellmanGroupExchangeSHA1, DSS, aes256-cbc/aes256-cbc, SHA1/SHA1
2010-12-15 16:10:00.521 INFO Sftp(1) SSH: Received banner: Company Information SSH Server 
2010-12-15 16:10:00.537 DEBUG Sftp(1) SSH: Allowed authentication methods: publickey, password.
2010-12-15 16:10:00.537 DEBUG Sftp(1) SSH: Trying password authentication for 'USER1'.
2010-12-15 16:10:00.568 DEBUG Sftp(1) SSH: Authentication successful.
2010-12-15 16:10:00.599 DEBUG Sftp(1) SSH: Requesting subsystem 'sftp'.
2010-12-15 16:10:00.631 INFO Sftp(1) Command: SSH_FXP_INIT (4)
2010-12-15 16:10:00.646 INFO Sftp(1) Response: SSH_FXP_VERSION (3, 0 extensions)
2010-12-15 16:10:00.646 INFO Sftp(1) Info: Using SFTP v3 on a Windows-like platform.
2010-12-15 16:10:00.662 INFO Sftp(1) Command: SSH_FXP_REALPATH (1, '.')
2010-12-15 16:10:00.678 INFO Sftp(1) Response: SSH_FXP_NAME (1, 1 item)
2010-12-15 16:10:00.678 INFO Sftp(1) Info: Current directory is '/'.
2010-12-15 16:10:00.693 INFO Sftp(1) Command: SSH_FXP_REALPATH (2, '/iPostPDF/')
2010-12-15 16:10:00.709 INFO Sftp(1) Response: SSH_FXP_NAME (2, 1 item)
2010-12-15 16:10:00.709 INFO Sftp(1) Command: SSH_FXP_STAT (3, '/iPostPDF')
2010-12-15 16:10:00.724 INFO Sftp(1) Response: SSH_FXP_ATTRS (3)
2010-12-15 16:10:00.740 INFO Sftp(1) Command: SSH_FXP_OPEN (4, '/iPostPDF/Message634280261996624970.Zip', 26)
2010-12-15 16:10:00.756 INFO Sftp(1) Response: SSH_FXP_HANDLE (4, 0x31)
2010-12-15 16:10:00.756 DEBUG Sftp(1) Info: Checking for abort flag [1].
2010-12-15 16:10:00.787 DEBUG Sftp(1) Command: SSH_FXP_WRITE (5, 0x31, 0, 28672 bytes)
2010-12-15 16:10:00.787 DEBUG Sftp(1) Info: Checking for abort flag [1].
2010-12-15 16:10:00.834 DEBUG Sftp(1) Command: SSH_FXP_WRITE (6, 0x31, 28672, 21047 bytes)
2010-12-15 16:10:00.834 DEBUG Sftp(1) Info: Checking for abort flag [1].
2010-12-15 16:10:00.834 DEBUG Sftp(1) Response: SSH_FXP_STATUS (5, 0, 'OK')
2010-12-15 16:10:00.849 DEBUG Sftp(1) Response: SSH_FXP_STATUS (6, 0, 'OK')
2010-12-15 16:10:00.849 INFO Sftp(1) Command: SSH_FXP_CLOSE (7, 0x31)
2010-12-15 16:10:00.865 INFO Sftp(1) Response: SSH_FXP_STATUS (7, 0, 'Ok')

Code copying zip files are handled like below.

sftpclient.Connect("Host", Sftp.DefaultPort, sshParams);
sftpclient.Login("USER1", "Password");
sftpclient.ChangeDirectory("TargetDir");
foreach (FileInfo file in files)
{
    sftpclient.PutFile(file.FullName, file.Name);
}
sftpclient.Disconnect();

Cheers Michael

Applies to: Rebex SFTP
by (13.3k points)
Would it be possible to create a communication log as described at http://www.rebex.net/kb/logging.aspx and either include it in your post or mail it to support@rebex.net for analysis? Could you also include the code which actually uploads the file?

1 Answer

0 votes
by (13.3k points)
edited

Thanks for the log. It looks ok. No obvious errors or incomplete file transfers. The file is transferred without any modification.

Possible reason 1: uploading incomplete file from local computer

Is it possible that you are uploading files which are still being written when the upload starts? E.g. some other application generates /iPostPDF/Message634280261996624970.Zip and before the process is completed, another application starts uploading this incomplete file.

To prevent it, try using the following code. It locks the file exclusively during upload. If the file is still being used by another process, it throws an exception.

foreach(FileInfo file in files)
{
    Console.WriteLine("Locking {0}, {1} bytes.", file.FullName, file.Length);
    long bytesUploaded = 0;

    using (Stream s = File.Open(file.FullName, FileMode.Open, 
           FileAccess.Read, FileShare.None))
    {
        Console.WriteLine("Uploading {0}", file.FullName);
        bytesUploaded = sftpclient.PutFile(s, file.Name);    
    }
    Console.WriteLine("{0} uploaded {1} bytes.\n", file.FullName, bytesUploaded);
}

Possible reason 2: processing file before being completely uploaded.

Another possibility might be that some application on the server tries to process the file even before it is completely uploaded. Can you check what triggers the upload?

...