scp

Transfer files from SFTP to FTP using scp command


How can I transfer files from SFTP to FTP using the scp command? I have tried this : scp -P21 /folder/file user@domaine.com:/folder But it is not working! It gives that error:

connection lost


Solution

  • The scp command doesn't support the FTP protocol, so you'll need to use an FTP client.

    The top answer to this question, "How to upload one file by FTP from command line?", suggests invoking the FTP client like this:

    $ ftp -n <<EOF
    open ftp.example.com
    user user secret
    put my-local-file.txt
    EOF
    

    That is, instruct the FTP client to connect to ftp.example.com, authenticate, and upload my-local-file.txt, all in a single shell command.


    Alternatively, you can use curl. This page goes into more detail, but basically you would run:

    curl --user user:secret --upload-file my-file.txt ftp://ftp.example.com/folder/
    

    Note the trailing slash in the URL - that makes curl upload the file into that folder with the same name as the original. If you don't add a trailing slash, e.g. ftp://ftp.example.com/folder, curl thinks that you want to rename the file to folder when uploading.

    If you don't want to specify the username and password on the command line, you can create a "netrc file":

    machine ftp.example.com login user password secret
    

    (Don't forget to restrict permissions with chmod 600 ./my-netrc-file!)

    And tell curl to use it with the option --netrc-file:

    curl --netrc-file ./my-netrc-file --upload-file /folder/file ftp://ftp.example.com/folder/