0

Per our IT department, I have to use a curl command to upload files to our SFTP server.

I use a Jenkins pipeline to build our artifacts on Windows build nodes, which are *.zip files, and this is the curl command I use

C:\> curl -V
curl 7.03.1 (Windows) libcurl/7.03.1 Schannel

C:\> curl -T ./build_artifact.zip -u 'user:password'  ftp://ftp.company.com/devops/test/build_artifact.zip --ftp-ssl-reqd --ftp-create-dirs -k

The file uploads correctly.

But when I download the file on my Mac and I unzip it, I get

$ unzip build_artifact.zip
Archive:  build_artifact.zip
  End-of-central-directory signature not found.  Either this file is not
  a zipfile, or it constitutes one disk of a multi-part archive.  In the
  latter case the central directory and zipfile comment will be found on
  the last disk(s) of this archive.
unzip:  cannot find zipfile directory in one of build_artifact.zip or
        build_artifact.zip.zip, and cannot find build_artifact.zip.ZIP, period.

Note if I execute the same curl command on my Mac to upload to the SFTP site, I can readily unzip the artifact when I subsequently download it.

Any clues on why this happens, and how to fix it?

2
  • Is there any chance the source path would differ on the build server? ./build_artifact.zip for example, might the command be running from a different start folder, which means the relative path doesn't point to a file? One quick check for this would be to look at the size of the file. If it's 0 bytes, you might be uploading "file not found", if that makes sense.
    – Fenton
    May 22 at 19:53
  • Thanks. It's the same file. I did check the file size and it's the same. On my scripts, I do a dir(env.WORKSPACE) {} before I execute the curl command, and the WORKSPACE is where the build_artifact.zip file is.
    – Chris F
    May 22 at 21:12

2 Answers 2

0

This could be the common known issue based on the upload transfer of binary files using the curl command on Windows.

By default, curl on a Windows device uses ASCII transfer mode which can cause issues with binary files like .zip archives. Whereas on a Mac device, the curl command uses binary transfer mode as default.

To avoid this, override the ASCII transfer method by implicitly specifying the transfer mode as binary, by using the --ftp-binary option.

See amended command below:

$ curl -T ./build_artifact.zip -u 'user:password' ftp://ftp.company.com/devops/test/build_artifact.zip --ftp-ssl-reqd --ftp-create-dirs -k --ftp-binary

1
  • I was hoping this would work. But I get curl: option --ftp-binary is unknown. Maybe later versions of curl have it, but apparently not curl v7.x.
    – Chris F
    May 30 at 14:25
0

Updating to the latest Git bash, which included curl v8.x fixed the issue.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.