cURL / Mailing Lists / curl-users / Single Mail

curl-users

Remove remote file issue using CURL SFTP

From: Sharma, Meghnath <meghnath.sharma_at_adeccona.com>
Date: Fri, 9 Jul 2010 17:49:30 -0400

Hi,

$ curl -V
curl 7.19.6 (powerpc-ibm-aix5.3.0.0) libcurl/7.19.6 GnuTLS/2.4.2 zlib/1.2.3 libidn/1.11 libssh2/1.2
Protocols: tftp ftp telnet dict http file https ftps scp sftp
Features: IDN IPv6 Largefile NTLM SSL libz

 I am using CURL SFTP to download the file and once downloaded, delete the remote file. I have a test machine (TEST A) within my company and a test machine on the client site (TEST B). The curl feature works for me on TEST A, but it doesn't work on TEST B.

TEST A: download and then deletion works beautifully
$ curl -v -u testuser:testpwd -O sftp://qzftap/~/testt.txt -Q '-rm testt.txt'
* About to connect() to qzftap port 22 (#0)
* Trying 10.60.20.163... connected
* Connected to qzftap (10.60.20.163) port 22 (#0)
* Failed to read known hosts from /appsQED1/edi/.ssh/known_hosts
* SSH host check: 0, key: AAAAB3NzaC1yc2EAAAABIwAAAQEAu05crPss/N2AIVeIgFRNfsCzOe8t+hMFL8Uy5crUnwHeHrIjPl+QZZiRLcRJRhq4xHDb1xvBXDoJXcQNx2yHsaaJhRcs9Tmat48IT94w3bL0kIqYhkGl1p41OkeOyJtnS5k5c0HfrztrOd6zqSvpHLuN2FHU8xtIy3AQAr5x5u1GdOfCyYifDeEpNTL2Gu+JzV2PDv2PebPXrdWjpTX8yQWu5pyMLMGWb6ZKAqkOnosMIbPdAcGEU3XuFJ0vVqQGPcUbOfqL63TO3qCBmVh9cWdLKZ5egq3eDJLfk0gVDkwHdBPbF1adu7RZnPgF/ARBNQIrMi0AWyMIUxvg9SC71w==
* SSH authentication methods available: publickey,password,keyboard-interactive
* Using ssh public key file /appsQED1/edi/.ssh/id_dsa.pub
* Using ssh private key file /appsQED1/edi/.ssh/id_dsa
* SSH public key authentication failed: Unable to open public key file
* Initialized password authentication
* Authentication complete
  % Total % Received % Xferd Average Speed Time Time Time Current
                                 Dload Upload Total Spent Left Speed
  0 8 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0{ [data not shown]
* Sending quote commands
  0 8 0 8 0 0 14 0 --:--:-- --:--:-- --:--:-- 14* Connection #0 to host qzftap left intact

 * Closing connection #0

TESTB: download works but deletion fails
$ curl -v -u adc_xfer: -O --key /apps2/edi/.ssh/id_rsa --pubkey /apps2/edi/.ssh/id_rsa.pub sftp://secureftp.ppp.com:10022/testt.txt -Q '-rm testt.txt'
* About to connect() to secureftp.ppp.com port 10022 (#0)
* Trying 170.100.108.16... connected
* Connected to secureftp.adp.com (170.100.108.16) port 10022 (#0)
* Failed to read known hosts from /appsQED1/edi/.ssh/known_hosts
* SSH host check: 0, key: AAAAB3NzaC1yc2EAAAADAQABAAABAQCWEoV6w3vnnIJs0Nv97Va/6YX5KY2x6oaTBycBYFEsZpIBkS2GvUOeRlUFGcJmS++Qt9EUUVNEAnM8/salP910FIySw2+T4f6BfpMFcqc+33dftkwOcANZ+RwPaBcOazQ0rdZPZjDcyoiLqkUe8VSrn9yZRlKsza51J5ddTHyNyBnXS5CVx/Dmw8qSipBZgCprSJigVblfeIk+2CwbKhB8jMLRWKlh67it76ettBCyqX5RwP/RONuJzJzSDxMJ+YuZQ4f+mPwo0Ik45koY2WpoHjnDr+au+hzcPcoNaGq0xrGHmWneayzjslvO4dvTW4HmEvezfpnSkDcAshLkDVNT
* SSH authentication methods available: publickey,password,keyboard-interactive
* Using ssh public key file /apps2/edi/.ssh/id_rsa.pub
* Using ssh private key file /apps2/edi/.ssh/id_rsa
* Initialized SSH public key authentication
* Authentication complete
  % Total % Received % Xferd Average Speed Time Time Time Current
                                 Dload Upload Total Spent Left Speed
  0 8 0 0 0 0 0 0 --:--:-- 0:00:04 --:--:-- 0{ [data not shown]
* Sending quote commands
* rm command failed: Permission denied
  0 8 0 8 0 0 1 0 --:--:-- 0:00:04 --:--:-- 1* Connection #0 to host secureftp.adp.com left intact

curl: (21) rm command failed: Permission denied
* Closing connection #0

As you can see above, I am getting 'Permission denied' issue while deleting the file (after download) on TEST B. In order to debug the issue, I executed the following scenarios on TEST B:

 1. curl -v -u adc_xfer: -O --key /apps2/edi/.ssh/id_rsa --pubkey /apps2/edi/.ssh/id_rsa.pub sftp://secureftp.ppp.com:10022/testt.txt -Q 'rm testt.txt' (This doesn't contain '-' sign before 'rm'): In this case, as expected, file was deleted successfully and the file download failed (because file was already deleted)
 2. curl -v -u adc_xfer: --key /apps2/edi/.ssh/id_rsa --pubkey /apps2/edi/.ssh/id_rsa.pub sftp://secureftp.ppp.com:10022/ -Q '-rm testt.txt' (This doesn't contain '-O' option and the file name in the SFTP url): In this case, as expected, file was deleted successfully.
 3. Manual SFTP (without CURL): When I manually login to the remote using SFTP and download and then delete the remote file, it works without any issue.

The successful execution of the above scenarios really amazed me as to why the 'file deletion after download' doesn't work with CURL SFTP. FYI, the file size is really small.
Could it be that file download and file deletion is happening at the same instant of time? If so, is there any way to correct that?

Thanks,
Megh

-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-users
FAQ: http://curl.haxx.se/docs/faq.html
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2010-07-09