传输后使用Curllib重命名文件(sftp)

时间:2012-10-10 16:44:02

标签: libcurl sftp

有一个类似的问题,但answer given does not solve my problem。这是我的代码

。 。     struct curl_slist * slist = NULL;

curl_easy_setopt( Curl, CURLOPT_UPLOAD, 1L);
curl_easy_setopt( Curl, CURLOPT_URL, "sftp://user:user@blah.blah.net:22/my_temp_file.txt");
curl_easy_setopt( Curl, CURLOPT_READFUNCTION, my_read_func));
curl_easy_setopt( Curl, CURLOPT_READDATA, &my_read_data);

slist = curl_slist_append( slist, "RNFR my_temp_file.txt");
slist = curl_slist_append( slist, "RNTO my_file.txt");

curl_easy_setopt( Curl, CURLOPT_POSTQUOTE,  slist);

rc = curl_easy_perform(Curl);

。 。

当我运行上面的内容时,我得到一个CURLE_QUOTE_ERROR(文件传输实际发生但重命名不会发生)。如果我省略帖子引用选项,那么所有工作(如前所述)都没有错误。

我已尝试使用所有不同格式的from / to名称,但无济于事。有什么想法吗?

2 个答案:

答案 0 :(得分:2)

文档说:

  

有效的SFTP命令是:chgrp,chmod,chown,ln,mkdir,pwd,   rename,rm,rmdir,symlink(参见curl(1))

因此,您可以使用“重命名”来重命名文件。

您使用的RNFR / RNTO是FTP命令,尽管名称相似,但与FTP相比,SFTP非常不同。

答案 1 :(得分:0)

这个SFTP版本的FTP cURL示例对我来说很好用:

version: '2'

networks:
  basic:

services:
  ca0:
    image: hyperledger/fabric-ca
    environment:
      - FABRIC_CA_HOME=/etc/hyperledger/fabric-ca-server
      - FABRIC_CA_SERVER_CA_NAME=ca0
    ports:
      - "7054:7054"
    command: sh -c 'fabric-ca-server start --ca.certfile /etc/hyperledger/fabric-ca-server-config/org1.example.com-cert.pem --ca.keyfile /etc/hyperledger/fabric-ca-server-config//home/nearih/Desktop/fabric-samples/basic-network/crypto-config/peerOrganizations/org1.example.com/ca/622b1c1e84517ffdf3b6c25281ca502b93daac647fc7853ef79dd35c78a5f201_sk -b admin:adminpw -d'
    volumes:
      - ./crypto-config/peerOrganizations/org1.example.com/ca/:/etc/hyperledger/fabric-ca-server-config
      - ~/Desktop/cer/org1:/etc/hyperledger/fabric-ca-server/msp/cacerts/
      - ~/Desktop/cer/org1:/etc/hyperledger/fabric-ca-server/msp/signcerts/
      - ~/Desktop/cer/org1:/etc/hyperledger/fabric-ca-server/msp/tlscacerts/
     # - ~/Desktop/cer:/etc/hyperledger/msp/users/Admin@org1.example.com/msp/admincerts
    container_name: ca0
    networks:
      - basic


  ca2:
    image: hyperledger/fabric-ca
    environment:
      - FABRIC_CA_HOME=/etc/hyperledger/fabric-ca-server
      - FABRIC_CA_SERVER_CA_NAME=ca2
    ports:
      - "8054:7054"
    command: sh -c 'fabric-ca-server start --ca.certfile /etc/hyperledger/fabric-ca-server-config/org2.example.com-cert.pem --ca.keyfile /etc/hyperledger/fabric-ca-server-config//home/nearih/Desktop/fabric-samples/basic-network/crypto-config/peerOrganizations/org1.example.com/ca/4ee0165e680c770aed2472ec7a2a88d2e5e2feddbccb379de483a9d81777ee19_sk -b admin:adminpw -d'    
    #command: sh -c 'fabric-ca-server start --ca.certfile /etc/hyperledger/fabric-ca-server-config/org2.example.com-cert.pem --ca.keyfile /etc/hyperledger/fabric-ca-server-config/4ee0165e680c770aed2472ec7a2a88d2e5e2feddbccb379de483a9d81777ee19_sk admin:adminpw -d'
    volumes:
      - ./crypto-config/peerOrganizations/org2.example.com/ca/:/etc/hyperledger/fabric-ca-server-config
      #- ~/Desktop/cer/:/etc/hyperledger/fabric-ca-server/msp/cacerts/
      - ~/Desktop/cer/org2:/etc/hyperledger/fabric-ca-server/msp/cacerts/
      - ~/Desktop/cer/org2:/etc/hyperledger/fabric-ca-server/msp/signcerts/
      - ~/Desktop/cer/org2:/etc/hyperledger/fabric-ca-server/msp/tlscacerts/
      #- ./crypto-config/peerOrganizations/org2.example.com/ca/:/etc/hyperledger/fabric-ca-server-config
      #- ~/Desktop/cer:/etc/hyperledger/msp/users/Admin@org2.example.com/msp/admincerts
    container_name: ca2
    networks:
      - basic

  orderer.example.com:
    container_name: orderer.example.com
    image: hyperledger/fabric-orderer
    environment:
      - ORDERER_GENERAL_LOGLEVEL=debug
      - ORDERER_GENERAL_LISTENADDRESS=0.0.0.0
      - ORDERER_GENERAL_GENESISMETHOD=file
      - ORDERER_GENERAL_GENESISFILE=/etc/hyperledger/configtx/basic-genesis.block
      - ORDERER_GENERAL_LOCALMSPID=OrdererMSP
      - ORDERER_GENERAL_LOCALMSPDIR=/etc/hyperledger/msp/orderer/msp
    working_dir: /opt/gopath/src/github.com/hyperledger/fabric/orderer
    command: orderer
    ports:
      - 7050:7050
    volumes:
        - ./config/:/etc/hyperledger/configtx
        - ./crypto-config/ordererOrganizations/example.com/orderers/orderer.example.com/:/etc/hyperledger/msp/orderer
        - ~/Desktop/fabric-samples/basic-network/:/etcetc/hyperledger/configtx
        #- ./crypto-config/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/:/etc/hyperledger/msp/peerOrg1
    networks:
      - basic

  peer0.org1.example.com:
    container_name: peer0.org1.example.com
    image: hyperledger/fabric-peer
    environment:
      - CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
      - CORE_PEER_ID=peer0.org1.example.com
      - CORE_LOGGING_PEER=debug
      - CORE_CHAINCODE_LOGGING_LEVEL=DEBUG
      - CORE_PEER_LOCALMSPID=Org1MSP
      - CORE_PEER_MSPCONFIGPATH=/etc/hyperledger/msp/peer/
      - CORE_PEER_ADDRESS=peer0.org1.example.com:7051
      # # the following setting starts chaincode containers on the same
      # # bridge network as the peers
      # # https://docs.docker.com/compose/networking/
      - CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=${COMPOSE_PROJECT_NAME}_basic
      - CORE_LEDGER_STATE_STATEDATABASE=CouchDB
      - CORE_LEDGER_STATE_COUCHDBCONFIG_COUCHDBADDRESS=couchdb:5984
      # The CORE_LEDGER_STATE_COUCHDBCONFIG_USERNAME and CORE_LEDGER_STATE_COUCHDBCONFIG_PASSWORD
      # provide the credentials for ledger to connect to CouchDB.  The username and password must
      # match the username and password set for the associated CouchDB.
      - CORE_LEDGER_STATE_COUCHDBCONFIG_USERNAME=
      - CORE_LEDGER_STATE_COUCHDBCONFIG_PASSWORD=
    working_dir: /opt/gopath/src/github.com/hyperledger/fabric
    command: peer node start
    # command: peer node start --peer-chaincodedev=true
    ports:
      - 7051:7051
      - 7053:7053
    volumes:
        - /var/run/:/host/var/run/
        - ./crypto-config/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/msp:/etc/hyperledger/msp/peer
        - ./crypto-config/peerOrganizations/org1.example.com/users:/etc/hyperledger/msp/users
        - ./config:/etc/hyperledger/configtx

    depends_on:
      - orderer.example.com
      - couchdb
    networks:
      - basic
  # start change

  peer1.org2.example.com:
    container_name: peer1.org2.example.com
    image: hyperledger/fabric-peer
    environment:
      - CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
      - CORE_PEER_ID=peer1.org2.example.com
      - CORE_LOGGING_PEER=debug
      - CORE_CHAINCODE_LOGGING_LEVEL=DEBUG
      - CORE_PEER_LOCALMSPID=Org1MSP
      - CORE_PEER_MSPCONFIGPATH=/etc/hyperledger/msp/peer/
      - CORE_PEER_ADDRESS=peer1.org2.example.com:7057
      # # the following setting starts chaincode containers on the same
      # # bridge network as the peers
      # # https://docs.docker.com/compose/networking/
      - CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=${COMPOSE_PROJECT_NAME}_basic
      - CORE_LEDGER_STATE_STATEDATABASE=CouchDB
      - CORE_LEDGER_STATE_COUCHDBCONFIG_COUCHDBADDRESS=couchdb2:5984
      # The CORE_LEDGER_STATE_COUCHDBCONFIG_USERNAME and CORE_LEDGER_STATE_COUCHDBCONFIG_PASSWORD
      # provide the credentials for ledger to connect to CouchDB.  The username and password must
      # match the username and password set for the associated CouchDB.
      - CORE_LEDGER_STATE_COUCHDBCONFIG_USERNAME=
      - CORE_LEDGER_STATE_COUCHDBCONFIG_PASSWORD=
    working_dir: /opt/gopath/src/github.com/hyperledger/fabric
    command: peer node start
    # command: peer node start --peer-chaincodedev=true
    ports:
      - 8051:7051
      - 8053:7053
    volumes:
        - /var/run/:/host/var/run/
        - ./crypto-config/peerOrganizations/org2.example.com/peers/peer1.org2.example.com/msp:/etc/hyperledger/msp/peer
        - ./crypto-config/peerOrganizations/org2.example.com/users:/etc/hyperledger/msp/users
        - ./config:/etc/hyperledger/configtx
    depends_on:
      - orderer.example.com
      - couchdb2
    networks:
      - basic

#end of change


  couchdb:
    container_name: couchdb
    image: hyperledger/fabric-couchdb
    # Populate the COUCHDB_USER and COUCHDB_PASSWORD to set an admin user and password
    # for CouchDB.  This will prevent CouchDB from operating in an "Admin Party" mode.
    environment:
      - COUCHDB_USER=
      - COUCHDB_PASSWORD=
    ports:
      - 5984:5984
    networks:
      - basic

#couchdb2

  couchdb2:
    container_name: couchdb2
    image: hyperledger/fabric-couchdb
    # Populate the COUCHDB_USER and COUCHDB_PASSWORD to set an admin user and password
    # for CouchDB.  This will prevent CouchDB from operating in an "Admin Party" mode.
    environment:
      - COUCHDB_USER=
      - COUCHDB_PASSWORD=
    ports:
      - 5985:5984
    networks:
      - basic

  cli:
    container_name: cli
    image: hyperledger/fabric-tools
    tty: true
    environment:
      - GOPATH=/opt/gopath
      - CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
      - CORE_LOGGING_LEVEL=DEBUG
      - CORE_PEER_ID=cli
      - CORE_PEER_ADDRESS=peer0.org1.example.com:7051
      - CORE_PEER_ADDRESS=peer1.org2.example.com:7051
      - CORE_PEER_LOCALMSPID=Org1MSP
      - CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp
      - CORE_CHAINCODE_KEEPALIVE=10
    working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer
    command: /bin/bash
    volumes:
        - /var/run/:/host/var/run/
        - ./../chaincode/:/opt/gopath/src/github.com/
        - ./crypto-config:/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/
        - ~/Desktop/cer/org1:/etc/hyperledger/fabric/msp/cacerts
        - ~/Desktop/cer/org1:/etc/hyperledger/fabric/msp/signcerts
        - ~/Desktop/cer/org1:/etc/hyperledger/fabric/msp/tlscacerts
        #- ~/Desktop/cer/org2:/etc/hyperledger/fabric/org2/msp/cacerts
        #- ~/Desktop/cer/org2:/etc/hyperledger/fabric/org2/msp/signcerts
        #- ~/Desktop/cer/org2:/etc/hyperledger/fabric/org2/msp/tlscacerts
    networks:
        - basic
    depends_on:
      - orderer.example.com
      - peer0.org1.example.com
      #- peer1.org2.example.com
      - couchdb
      - couchdb2

  cli2:
    container_name: cli2
    image: hyperledger/fabric-tools
    tty: true
    environment:
      - GOPATH=/opt/gopath
      - CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
      - CORE_LOGGING_LEVEL=DEBUG
      - CORE_PEER_ID=cli2
      - CORE_PEER_ADDRESS=peer0.org1.example.com:7051
      - CORE_PEER_ADDRESS=peer1.org2.example.com:7051
      - CORE_PEER_LOCALMSPID=Org1MSP
      - CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp
      - CORE_CHAINCODE_KEEPALIVE=10
    working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer
    command: /bin/bash
    volumes:
        - /var/run/:/host/var/run/
        - ./../chaincode/:/opt/gopath/src/github.com/
        - ./crypto-config:/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/
        - ~/Desktop/cer/org1:/etc/hyperledger/fabric/org1/msp/cacerts
        - ~/Desktop/cer/org1:/etc/hyperledger/fabric/org1/msp/signcerts
        - ~/Desktop/cer/org1:/etc/hyperledger/fabric/org1/msp/tlscacerts
        #- ~/Desktop/cer/org2:/etc/hyperledger/fabric/msp/cacerts
        #- ~/Desktop/cer/org2:/etc/hyperledger/fabric/msp/signcerts
        #- ~/Desktop/cer/org2:/etc/hyperledger/fabric/msp/tlscacerts
    networks:
        - basic
    depends_on:
      - orderer.example.com
      #- peer0.org1.example.com
      - peer1.org2.example.com
      - couchdb
      - couchdb2