Find the answer to your Linux question:
Results 1 to 8 of 8
Hi, I'm trying to write a shell script to sftp some files to a server...I'm trying to connect to the server like the below using curl (version 7.17.1) (note replace ...
  1. #1
    Just Joined!
    Join Date
    Apr 2009
    Posts
    6

    sftp with curl non-standard port issue?

    Hi, I'm trying to write a shell script to sftp some files to a server...I'm trying to connect to the server like the below using curl (version 7.17.1) (note replace "AT" with at symbol)

    /usr/local/bin/curl -v --ftp-ssl-reqd ftp://user:passATftp.something.com:60022

    It looks like it connects but it does not authenticate. It stops after outputting the below:

    Connected to ftp.something.com (199.81.193.200) port 60022 (#0)
    < SSH-2.0-SftpSSHD_1.2.3_Comments

    I think maybe it has something to do w/ the non-standard port but I'm not sure? I can connect with the sftp program but I dont think I can specify a password on the command line. Was hoping someone has any suggestions?
    Thanks!

  2. #2
    Linux Guru
    Join Date
    Nov 2007
    Posts
    1,695
    You may want to explore using sftp with its batch mode option.

    Code:
    man sftp
    
    -b batchfile
                 Batch mode reads a series of commands from an input batchfile instead of stdin.  Since it lacks user interaction it should be used in conjunction
                 with non-interactive authentication.  A batchfile of ‘-’ may be used to indicate standard input.  sftp will abort if any of the following commands
                 fail: get, put, rename, ln, rm, mkdir, chdir, ls, lchdir, chmod, chown, chgrp, lpwd, df, and lmkdir.  Termination on error can be suppressed on a
                 command by command basis by prefixing the command with a ‘-’ character (for example, -rm /tmp/blah*).

  3. #3
    Just Joined!
    Join Date
    Apr 2009
    Posts
    6
    Thanks, that may work if I can find some example batch files. Can anyone provide an explanation as to why curl is not authenticating though ?

    Thanks

  4. #4
    Just Joined!
    Join Date
    Apr 2009
    Posts
    6
    Hm, it appears that I also have to have a password-less login setup with the host for the sftp batch method to work...unfortunately I don't have any control over that.

  5. #5
    Linux Guru
    Join Date
    Nov 2007
    Posts
    1,695
    Have you looked at the sftp help/man page?

    Code:
    -u/--user <user[:password]> Set server user and password
    Code:
    curl -u user:pass --ftp-ssl-reqd ftp://someplace:<port>
    ???

  6. #6
    Just Joined!
    Join Date
    Apr 2009
    Posts
    6
    Yeah that is basically the format I am using in my first post with curl -- like I said it just spits out some output and hangs (in verbose mode -- not in verbose it doesnt output anything, just hangs on the cursor). This is the full output in verbose mode (server anonymized):

    * About to connect() to XXXX
    * Trying XXXX ... connected
    * Connected to XXXX (XXXX.XX.XX.XXX) port 60022 (#0)
    < SSH-2.0-SftpSSHD_1.2.3_Comments
    (..HANG here)


    I have tried this format as well, same result:
    curl -u userass --ftp-ssl-reqd ftp://someplace:<port>

    If I take off the --ftp-ssl-reqd option and port, it will connect in non-ssl mode (which I dont want).

    I have other processes that connect to a server successfully using this method...only thing I can think of is it has something to do w/ the port ?

  7. #7
    Linux Guru
    Join Date
    Nov 2007
    Posts
    1,695
    cURL Manual

    You are confusing me...

    FTP with SSL encryption is ftps.

    File transfer using SSH with FTP-like commands is sftp.

    Per the cURL manual:

    Code:
    Get a file from an SSH server using SFTP:
     
            curl -u username sftp://shell.example.com/etc/issue
    Your error seems to show an SSH server, but the connection method you are telling cURL to use is FTP with SSL.

  8. #8
    Just Joined!
    Join Date
    Apr 2009
    Posts
    6
    That makes sense. Thats why this is in the newb section

    Ive determined that in order to make curl work with sftp / ssh I need to configure it with this option:

    ./configure --with-libssh2

    as per curls install documentation:
    "To get support for SCP and SFTP, build with --with-libssh2 and have
    libssh2 0.16 or later installed."

    Thanks for the insight.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...