Copy file to server that support only SSH2

Dear community,
I have to copy a file from Red Hat to another server that supports only SSH2.

SFTP command from Red Hat works fine, but since I have to insert SFTP command into a script, is it possibile to PUT file using SFTP in "one" line code?
Or, anyway, without using external file?

This works, but instead to put, it GET the file FROM the server:

sftp user@10.99.1.12:/root/filetoput

sftp and scp use the exact same protocol; if you can connect with sftp, you can connect with scp.

scp local-file username@host:/path/to/remote/file

With scp I got this message:

# scp local-file user@10.99.1.12:/path/to/remote/file
scp1 compatibility mode is not supported.

This because, as far I know, SCP supports only SSH v1 and destination server accept only connection with SSH v2.

Instead with SFTP, I got:

sftp user@10.99.1.12
sftp> put test.sh
Uploading test.sh to /SYS$SYSDEVICE/USER/test.sh
test.sh                                                                                           100%  108     0.1KB/s   00:00   

So, it's currently working, the only things is that SFTP works in interactive mode, so that's why I'm asking if there is a way to put the command in one line without using external file.

Three seconds of checking in man scp finds this:

     The options are as follows:

     -1      Forces scp to use protocol 1.

     -2      Forces scp to use protocol 2.

...so I don't think that's accurate at all.

YEP! Already tried without success: :frowning:

# scp -2 server1.log user@10.99.1.12:server1.log
         This is SERV11, Unauthorized Access Prohibited.
scp1 compatibility mode is not supported.

The server machine is OpenVMS OS. Last days I had found a solution with pscp (putty scp). But, if one of the server is unreachable (e.g. for maintenance), the PSCP hangs. That's no good since the script runs from crontab every 5 minutes!
With OpenSSH I can setup the TimeoutConnection to a few seconds, so if the server is down, the script continues with the copy to the other servers after a few seconds.

I cannot find any way to downgrade the timeout on PSCP as already do on OpenSSH.

sftp -b - user@host <<< 'put file'

You can omit the "-b -" part, but then sftp will always exit with 0 even if it fails.

1 Like

Thank you binlib, this is a nice workaround, but, at this point, I prefer to use an external sftp command file rather than a WA. This for script stability! :wink: